Netdev List
 help / color / mirror / Atom feed
* [PATCH 0/5] LLC SOCK_DGRAM enhancements
@ 2006-05-24  0:04 Stephen Hemminger
  2006-05-24  0:04 ` [PATCH 1/5] llc: allow datagram recvmsg Stephen Hemminger
                   ` (5 more replies)
  0 siblings, 6 replies; 8+ messages in thread
From: Stephen Hemminger @ 2006-05-24  0:04 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo; +Cc: netdev

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.

--


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 1/5] llc: allow datagram recvmsg
  2006-05-24  0:04 [PATCH 0/5] LLC SOCK_DGRAM enhancements Stephen Hemminger
@ 2006-05-24  0:04 ` Stephen Hemminger
  2006-05-24  0:04 ` [PATCH 2/5] llc: use rcu_dereference on receive handler Stephen Hemminger
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: Stephen Hemminger @ 2006-05-24  0:04 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo; +Cc: netdev

[-- Attachment #1: llc-dgram-recv.patch --]
[-- Type: text/plain, Size: 884 bytes --]

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.

Signed-off-by: Stephen Hemminger <shemminger@osdl.org>
--- llc.orig/net/llc/af_llc.c
+++ llc/net/llc/af_llc.c
@@ -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

--


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 2/5] llc: use rcu_dereference on receive handler
  2006-05-24  0:04 [PATCH 0/5] LLC SOCK_DGRAM enhancements Stephen Hemminger
  2006-05-24  0:04 ` [PATCH 1/5] llc: allow datagram recvmsg Stephen Hemminger
@ 2006-05-24  0:04 ` Stephen Hemminger
  2006-05-24  0:04 ` [PATCH 3/5] llc: allow applications to get copy of kernel datagrams Stephen Hemminger
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: Stephen Hemminger @ 2006-05-24  0:04 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo; +Cc: netdev

[-- Attachment #1: llc-rcvfunc-rcu.patch --]
[-- Type: text/plain, Size: 902 bytes --]

The receive hander pointer might be modified during network changes
of protocol. So use rcu_dereference (only matters on alpha).

Signed-off-by: Stephen Hemminger <shemminger@osdl.org>
--- br.orig/net/llc/llc_input.c
+++ br/net/llc/llc_input.c
@@ -142,6 +142,8 @@ int llc_rcv(struct sk_buff *skb, struct 
 	struct 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);

--


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 3/5] llc: allow applications to get copy of kernel datagrams
  2006-05-24  0:04 [PATCH 0/5] LLC SOCK_DGRAM enhancements Stephen Hemminger
  2006-05-24  0:04 ` [PATCH 1/5] llc: allow datagram recvmsg Stephen Hemminger
  2006-05-24  0:04 ` [PATCH 2/5] llc: use rcu_dereference on receive handler Stephen Hemminger
@ 2006-05-24  0:04 ` Stephen Hemminger
  2006-05-31 17:00   ` [PATCH 3/5] llc: allow applications to get copy of kernel datagrams (redo) Stephen Hemminger
  2006-05-24  0:04 ` [PATCH 4/5] llc: use more efficient ether address routines Stephen Hemminger
                   ` (2 subsequent siblings)
  5 siblings, 1 reply; 8+ messages in thread
From: Stephen Hemminger @ 2006-05-24  0:04 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo; +Cc: netdev

[-- Attachment #1: llc-rcv-sap.patch --]
[-- Type: text/plain, Size: 781 bytes --]

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.

Signed-off-by: Stephen Hemminger <shemminger@osdl.org>
--- llc.orig/net/llc/llc_input.c
+++ llc/net/llc/llc_input.c
@@ -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]))

--


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 4/5] llc: use more efficient ether address routines
  2006-05-24  0:04 [PATCH 0/5] LLC SOCK_DGRAM enhancements Stephen Hemminger
                   ` (2 preceding siblings ...)
  2006-05-24  0:04 ` [PATCH 3/5] llc: allow applications to get copy of kernel datagrams Stephen Hemminger
@ 2006-05-24  0:04 ` Stephen Hemminger
  2006-05-24  0:04 ` [PATCH 5/5] llc: add multicast support for datagrams Stephen Hemminger
  2006-05-25 22:11 ` [PATCH 0/5] LLC SOCK_DGRAM enhancements David Miller
  5 siblings, 0 replies; 8+ messages in thread
From: Stephen Hemminger @ 2006-05-24  0:04 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo; +Cc: netdev

[-- Attachment #1: llc-ether-routines.patch --]
[-- Type: text/plain, Size: 1926 bytes --]

Use more cache efficient Ethernet address manipulation functions
in etherdevice.h.

Signed-off-by: Stephen Hemminger <shemminger@osdl.org>

--- llc.orig/include/net/llc_if.h
+++ llc/include/net/llc_if.h
@@ -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,
--- br.orig/net/llc/llc_if.c
+++ br/net/llc/llc_if.c
@@ -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

--


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 5/5] llc: add multicast support for datagrams
  2006-05-24  0:04 [PATCH 0/5] LLC SOCK_DGRAM enhancements Stephen Hemminger
                   ` (3 preceding siblings ...)
  2006-05-24  0:04 ` [PATCH 4/5] llc: use more efficient ether address routines Stephen Hemminger
@ 2006-05-24  0:04 ` Stephen Hemminger
  2006-05-25 22:11 ` [PATCH 0/5] LLC SOCK_DGRAM enhancements David Miller
  5 siblings, 0 replies; 8+ messages in thread
From: Stephen Hemminger @ 2006-05-24  0:04 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo; +Cc: netdev

[-- Attachment #1: llc-mc-recv.patch --]
[-- Type: text/plain, Size: 2455 bytes --]

Allow mulitcast reception of datagrams (similar to UDP).
All sockets bound to the same SAP receive a clone.

Signed-off-by: Stephen Hemminger <shemminger@osdl.org>

--- llc.orig/include/net/llc_if.h
+++ llc/include/net/llc_if.h
@@ -79,6 +79,10 @@ static inline int llc_addrany(const stru
 	return 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.
--- br.orig/net/llc/llc_sap.c
+++ br/net/llc/llc_sap.c
@@ -282,7 +282,7 @@ static void llc_sap_rcv(struct llc_sap *
  *	mac, and local sap. Returns pointer for socket found, %NULL otherwise.
  */
 static struct sock *llc_lookup_dgram(struct llc_sap *sap,
-				     struct llc_addr *laddr)
+				     const struct llc_addr *laddr)
 {
 	struct sock *rc;
 	struct hlist_node *node;
@@ -304,19 +304,62 @@ found:
 	return rc;
 }
 
+/**
+ * 	llc_sap_mcast - Deliver multicast PDU's to all matching datagram sockets.
+ *	@sap: SAP
+ *	@laddr: address of local LLC (MAC + SAP)
+ *
+ *	Search socket list of the SAP and finds connections with same sap.
+ *	Deliver clone to each.
+ */
+static void llc_sap_mcast(struct llc_sap *sap,
+			  const struct llc_addr *laddr,
+			  struct sk_buff *skb)
+{
+	struct sock *sk;
+	struct hlist_node *node;
+
+	read_lock_bh(&sap->sk_list.lock);
+	sk_for_each(sk, node, &sap->sk_list.list) {
+		struct llc_sock *llc = llc_sk(sk);
+		struct sk_buff *skb1;
+
+		if (sk->sk_type != SOCK_DGRAM)
+			continue;
+
+		if (llc->laddr.lsap != laddr->lsap)
+			continue;
+
+		skb1 = skb_clone(skb, GFP_ATOMIC);
+		if (!skb1)
+			break;
+
+		sock_hold(sk);
+		skb_set_owner_r(skb1, sk);
+		llc_sap_rcv(sap, skb1);
+		sock_put(sk);
+	}
+	read_unlock_bh(&sap->sk_list.lock);
+}
+
+
 void llc_sap_handler(struct llc_sap *sap, struct sk_buff *skb)
 {
 	struct llc_addr laddr;
-	struct sock *sk;
 
 	llc_pdu_decode_da(skb, laddr.mac);
 	llc_pdu_decode_dsap(skb, &laddr.lsap);
 
-	sk = llc_lookup_dgram(sap, &laddr);
-	if (sk) {
-		skb_set_owner_r(skb, sk);
-		llc_sap_rcv(sap, skb);
-		sock_put(sk);
-	} else
+	if (llc_mac_multicast(laddr.mac)) {
+		llc_sap_mcast(sap, &laddr, skb);
 		kfree_skb(skb);
+	} else {
+		struct sock *sk = llc_lookup_dgram(sap, &laddr);
+		if (sk) {
+			skb_set_owner_r(skb, sk);
+			llc_sap_rcv(sap, skb);
+			sock_put(sk);
+		} else
+			kfree_skb(skb);
+	}
 }

--


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 0/5] LLC SOCK_DGRAM enhancements
  2006-05-24  0:04 [PATCH 0/5] LLC SOCK_DGRAM enhancements Stephen Hemminger
                   ` (4 preceding siblings ...)
  2006-05-24  0:04 ` [PATCH 5/5] llc: add multicast support for datagrams Stephen Hemminger
@ 2006-05-25 22:11 ` David Miller
  5 siblings, 0 replies; 8+ messages in thread
From: David Miller @ 2006-05-25 22:11 UTC (permalink / raw)
  To: shemminger; +Cc: acme, netdev

From: Stephen Hemminger <shemminger@osdl.org>
Date: Tue, 23 May 2006 17:04:14 -0700

> 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.

All applied, thanks Stephen.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 3/5] llc: allow applications to get copy of kernel datagrams (redo)
  2006-05-24  0:04 ` [PATCH 3/5] llc: allow applications to get copy of kernel datagrams Stephen Hemminger
@ 2006-05-31 17:00   ` Stephen Hemminger
  0 siblings, 0 replies; 8+ messages in thread
From: Stephen Hemminger @ 2006-05-31 17:00 UTC (permalink / raw)
  To: Andrew Morton, David S. Miller; +Cc: Arnaldo Carvalho de Melo, netdev

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.

Signed-off-by: Stephen Hemminger <shemminger@osdl.org>

--- br.orig/net/llc/llc_input.c
+++ br/net/llc/llc_input.c
@@ -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]))

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2006-05-31 17:00 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-05-24  0:04 [PATCH 0/5] LLC SOCK_DGRAM enhancements Stephen Hemminger
2006-05-24  0:04 ` [PATCH 1/5] llc: allow datagram recvmsg Stephen Hemminger
2006-05-24  0:04 ` [PATCH 2/5] llc: use rcu_dereference on receive handler Stephen Hemminger
2006-05-24  0:04 ` [PATCH 3/5] llc: allow applications to get copy of kernel datagrams Stephen Hemminger
2006-05-31 17:00   ` [PATCH 3/5] llc: allow applications to get copy of kernel datagrams (redo) Stephen Hemminger
2006-05-24  0:04 ` [PATCH 4/5] llc: use more efficient ether address routines Stephen Hemminger
2006-05-24  0:04 ` [PATCH 5/5] llc: add multicast support for datagrams Stephen Hemminger
2006-05-25 22:11 ` [PATCH 0/5] LLC SOCK_DGRAM enhancements David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox