LLC SOCK_DGRAM enhancements
Subsystems (3)
cover LLC SOCK_DGRAM enhancements
I want to use AF_LLC and SOCK_DGRAM for handling Spanning Tree Protocol packets in user space. The existing code doesn't work and also doesn't support multicast. These basic problems and add some cleanups.
--
PATCH 1/5 llc: allow datagram recvmsg
LLC receive is broken for SOCK_DGRAM.
If an application does recv() on a datagram socket and there is no data present, don't return "not connected". Instead, just do normal datagram semantics.
net/llc/af_llc.c +2 -2
@@ -674,7 +674,7 @@ static int llc_ui_recvmsg(struct kiocb *lock_sock (sk); copied = -ENOTCONN ; -if (sk->sk_state ==TCP_LISTEN ) +if (unlikely (sk->sk_type ==SOCK_STREAM && sk->sk_state ==TCP_LISTEN )) goto out; timeo =sock_rcvtimeo (sk, nonblock);
@@ -733,7 +733,7 @@ static int llc_ui_recvmsg(struct kiocb *if (sk->sk_shutdown &RCV_SHUTDOWN )break ; -if (sk->sk_state ==TCP_CLOSE ) { +if (sk->sk_type ==SOCK_STREAM && sk->sk_state ==TCP_CLOSE ) {if (!sock_flag (sk,SOCK_DONE )) {/* * This occurs when user tries to read
--
PATCH 2/5 llc: use rcu_dereference on receive handler
In reply to Stephen HemmingerThe receive hander pointer might be modified during network changes of protocol. So use rcu_dereference (only matters on alpha).
net/llc/llc_input.c +5 -2
@@ -142,6 +142,8 @@ int llc_rcv(struct sk_buff *skb, structstruct llc_sap *sap;struct llc_pdu_sn *pdu;int dest; +int (*rcv)(struct sk_buff *,struct net_device *, +struct packet_type *,struct net_device *);/* * When the interface is in promisc. mode, drop all the crap that it
@@ -169,8 +171,9 @@ int llc_rcv(struct sk_buff *skb, struct* First the upper layer protocols that don't need the full * LLC functionality */ -if (sap->rcv_func) { - sap->rcv_func (skb, dev, pt, orig_dev); + rcv =rcu_dereference (sap->rcv_func); +if (rcv) { +rcv (skb, dev, pt, orig_dev); goto out_put; } dest =llc_pdu_type (skb);
--
PATCH 3/5 llc: allow applications to get copy of kernel datagrams
In reply to Stephen HemmingerIt is legal for an application to bind to a SAP that is also being used by the kernel. This happens if the bridge module binds to the STP SAP, and the user wants to have a daemon for STP as well. It is possible to have kernel doing STP on one bridge, but let application do RSTP on another bridge.
net/llc/llc_input.c +3 -1
@@ -173,8 +173,10 @@ int llc_rcv(struct sk_buff *skb, struct*/ rcv =rcu_dereference (sap->rcv_func);if (rcv) { +struct sk_buff *cskb =skb_clone (skb,GFP_ATOMIC ); +if (cskb) +rcv (cskb, dev, pt, orig_dev);rcv (skb, dev, pt, orig_dev); - goto out_put; } dest =llc_pdu_type (skb);if (unlikely (!dest || !llc_type_handlers[dest -1 ]))
--
PATCH 3/5 llc: allow applications to get copy of kernel datagrams (redo)
It is legal for an application to bind to a SAP that is also being used by the kernel. This happens if the bridge module binds to the STP SAP, and the user wants to have a daemon for STP as well. It is possible to have kernel doing STP on one bridge, but let application do RSTP on another bridge.
Previous version of the patch was broken and called rcv() twice.
net/llc/llc_input.c +5 -2
@@ -173,8 +173,11 @@ int llc_rcv(struct sk_buff *skb, struct*/ rcv =rcu_dereference (sap->rcv_func);if (rcv) { -rcv (skb, dev, pt, orig_dev); - goto out_put; +struct sk_buff *skb2; + + skb2 =skb_clone (skb,GFP_ATOMIC ); +if (skb2) +rcv (skb2, dev, pt, orig_dev); } dest =llc_pdu_type (skb);if (unlikely (!dest || !llc_type_handlers[dest -1 ]))
PATCH 4/5 llc: use more efficient ether address routines
In reply to Stephen HemmingerUse more cache efficient Ethernet address manipulation functions in etherdevice.h.
include/net/llc_if.h +6 -7
@@ -16,6 +16,7 @@#include <linux/if.h> #include <linux/if_arp.h> #include <linux/llc.h> +#include <linux/etherdevice.h> #include <net/llc.h> #define LLC_DATAUNIT_PRIM 1
@@ -61,8 +62,6 @@#define LLC_STATUS_CONFLICT 7/* disconnect conn */ #define LLC_STATUS_RESET_DONE 8/* */ -extern u8 llc_mac_null_var[IFHWADDRLEN ]; -/** * llc_mac_null - determines if a address is a null mac address * @mac: Mac address to test if null.
@@ -70,12 +69,12 @@ extern u8 llc_mac_null_var[IFHWADDRLEN];* Determines if a given address is a null mac address. Returns 0 if the * address is not a null mac, 1 if the address is a null mac. */ -static __inline__int llc_mac_null (u8 *mac) +static inline int llc_mac_null (const u8 *mac) { -return !memcmp (mac, llc_mac_null_var,IFHWADDRLEN ); +return is_zero_ether_addr (mac); } -static __inline__int llc_addrany (struct llc_addr *addr) +static inline int llc_addrany (const struct llc_addr *addr) {return llc_mac_null (addr->mac) && !addr->lsap; }
@@ -89,9 +88,9 @@ static __inline__ int llc_addrany(struct* is not a complete match up to len, 1 if a complete match up to len is * found. */ -static __inline__int llc_mac_match (u8 *mac1,u8 *mac2) +static inline int llc_mac_match (const u8 *mac1,const u8 *mac2) { -return !memcmp (mac1, mac2,IFHWADDRLEN ); +return !compare_ether_addr (mac1, mac2); } extern int llc_establish_connection(struct sock *sk, u8 *lmac,
net/llc/llc_if.c +0 -2
@@ -26,8 +26,6 @@#include <net/llc_c_st.h> #include <net/tcp_states.h> -u8 llc_mac_null_var[IFHWADDRLEN ]; -/** * llc_build_and_send_pkt - Connection data sending for upper layers. * @sk: connection
--
PATCH 5/5 llc: add multicast support for datagrams
In reply to Stephen HemmingerAllow mulitcast reception of datagrams (similar to UDP). All sockets bound to the same SAP receive a clone.
include/net/llc_if.h +4 -0
@@ -79,6 +79,10 @@ static inline int llc_addrany(const strureturn llc_mac_null (addr->mac) && !addr->lsap; } +static inline int llc_mac_multicast (const u8 *mac) +{ +return is_multicast_ether_addr (mac); +}/** * llc_mac_match - determines if two mac addresses are the same * @mac1: First mac address to compare.
net/llc/llc_sap.c +51 -8
77 lines not on this page · raw message
--
David Miller
maintainerFrom: Stephen Hemminger <[email protected]>
Date: Tue, 23 May 2006 17:04:14 -0700
Quoted 4 lines
I want to use
AF_LLCandSOCK_DGRAMfor handling Spanning Tree Protocol packets in user space. The existing code doesn't work and also doesn't support multicast. These basic problems and add some cleanups.
All applied, thanks Stephen.