Skip to contentSkip to conversation

decouple llc/bridge

PATCH In review Dave Jones 3 participants 4 messages Apr 7, 2022 – Apr 8, 2022

Subsystems (3)
lore
Share & tools
lore

Dave Jones

author
#0 lore raw

PATCH 1/1 decouple llc/bridge

I was wondering why the llc code was getting compiled and it turned out to be because I had bridging enabled. It turns out to only needs it for a single function (llc_mac_hdr_init).

Converting this to a static inline like the other llc functions it uses allows to decouple the dependency

net/llc.h +29 -2
index e250dca03963..edcb120ee6b0 100644
@@ -13,6 +13,7 @@
  */
 
 #include <linux/if.h>
+#include <linux/if_arp.h>
 #include <linux/if_ether.h>
 #include <linux/list.h>
 #include <linux/spinlock.h>
@@ -100,8 +101,34 @@ extern struct list_head llc_sap_list;
 int llc_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt,
 	    struct net_device *orig_dev);
 
-int llc_mac_hdr_init(struct sk_buff *skb, const unsigned char *sa,
-		     const unsigned char *da);
+/**
+ *      llc_mac_hdr_init - fills MAC header fields
+ *      @skb: Address of the frame to initialize its MAC header
+ *      @sa: The MAC source address
+ *      @da: The MAC destination address
+ *
+ *      Fills MAC header fields, depending on MAC type. Returns 0, If MAC type
+ *      is a valid type and initialization completes correctly 1, otherwise.
+ */
+static inline int llc_mac_hdr_init(struct sk_buff *skb,
+				   const unsigned char *sa, const unsigned char *da)
+{
+	int rc = -EINVAL;
+
+	switch (skb->dev->type) {
+	case ARPHRD_ETHER:
+	case ARPHRD_LOOPBACK:
+		rc = dev_hard_header(skb, skb->dev, ETH_P_802_2, da, sa,
+				     skb->len);
+		if (rc > 0)
+			rc = 0;
+		break;
+	default:
+		break;
+	}
+	return rc;
+}
+
 
 void llc_add_pack(int type,
 		  void (*handler)(struct llc_sap *sap, struct sk_buff *skb));
802/Kconfig +0 -1
index aaa83e888240..8bea5d1d5118 100644
@@ -1,7 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0-only
 config STP
 	tristate
-	select LLC
 
 config GARP
 	tristate
bridge/Kconfig +0 -1
index 3c8ded7d3e84..c011856d3386 100644
@@ -5,7 +5,6 @@
 
 config BRIDGE
 	tristate "802.1d Ethernet Bridging"
-	select LLC
 	select STP
 	depends on IPV6 || IPV6=n
 	help
llc/llc_output.c +0 -28
index 5a6466fc626a..ad66886ed141 100644
@@ -13,34 +13,6 @@
 #include <net/llc.h>
 #include <net/llc_pdu.h>
 
-/**
- *	llc_mac_hdr_init - fills MAC header fields
- *	@skb: Address of the frame to initialize its MAC header
- *	@sa: The MAC source address
- *	@da: The MAC destination address
- *
- *	Fills MAC header fields, depending on MAC type. Returns 0, If MAC type
- *	is a valid type and initialization completes correctly 1, otherwise.
- */
-int llc_mac_hdr_init(struct sk_buff *skb,
-		     const unsigned char *sa, const unsigned char *da)
-{
-	int rc = -EINVAL;
-
-	switch (skb->dev->type) {
-	case ARPHRD_ETHER:
-	case ARPHRD_LOOPBACK:
-		rc = dev_hard_header(skb, skb->dev, ETH_P_802_2, da, sa,
-				     skb->len);
-		if (rc > 0)
-			rc = 0;
-		break;
-	default:
-		break;
-	}
-	return rc;
-}
-
 /**
  *	llc_build_and_send_ui_pkt - unitdata request interface for upper layers
  *	@sap: sap to use
#1 lore raw
Quoted 111 lines · On Thu, 7 Apr 2022 11:12:17 -0400 Dave Jones <[email protected]> wrote:

I was wondering why the llc code was getting compiled and it turned out to be because I had bridging enabled. It turns out to only needs it for a single function (llc_mac_hdr_init).

Converting this to a static inline like the other llc functions it uses allows to decouple the dependency

net/llc.h +29 -2
index e250dca03963..edcb120ee6b0 100644
@@ -13,6 +13,7 @@
  */
 
 #include <linux/if.h>
+#include <linux/if_arp.h>
 #include <linux/if_ether.h>
 #include <linux/list.h>
 #include <linux/spinlock.h>
@@ -100,8 +101,34 @@ extern struct list_head llc_sap_list;
 int llc_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt,
 	    struct net_device *orig_dev);
 
-int llc_mac_hdr_init(struct sk_buff *skb, const unsigned char *sa,
-		     const unsigned char *da);
+/**
+ *      llc_mac_hdr_init - fills MAC header fields
+ *      @skb: Address of the frame to initialize its MAC header
+ *      @sa: The MAC source address
+ *      @da: The MAC destination address
+ *
+ *      Fills MAC header fields, depending on MAC type. Returns 0, If MAC type
+ *      is a valid type and initialization completes correctly 1, otherwise.
+ */
+static inline int llc_mac_hdr_init(struct sk_buff *skb,
+				   const unsigned char *sa, const unsigned char *da)
+{
+	int rc = -EINVAL;
+
+	switch (skb->dev->type) {
+	case ARPHRD_ETHER:
+	case ARPHRD_LOOPBACK:
+		rc = dev_hard_header(skb, skb->dev, ETH_P_802_2, da, sa,
+				     skb->len);
+		if (rc > 0)
+			rc = 0;
+		break;
+	default:
+		break;
+	}
+	return rc;
+}
+
 
 void llc_add_pack(int type,
 		  void (*handler)(struct llc_sap *sap, struct sk_buff *skb));
802/Kconfig +0 -1
index aaa83e888240..8bea5d1d5118 100644
@@ -1,7 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0-only
 config STP
 	tristate
-	select LLC
 
 config GARP
 	tristate
bridge/Kconfig +0 -1
index 3c8ded7d3e84..c011856d3386 100644
@@ -5,7 +5,6 @@
 
 config BRIDGE
 	tristate "802.1d Ethernet Bridging"
-	select LLC
 	select STP
 	depends on IPV6 || IPV6=n
 	help
llc/llc_output.c +0 -21
index 5a6466fc626a..ad66886ed141 100644
@@ -13,34 +13,6 @@
 #include <net/llc.h>
 #include <net/llc_pdu.h>
 
-/**
- *	llc_mac_hdr_init - fills MAC header fields
- *	@skb: Address of the frame to initialize its MAC header
- *	@sa: The MAC source address
- *	@da: The MAC destination address
- *
- *	Fills MAC header fields, depending on MAC type. Returns 0, If MAC type
- *	is a valid type and initialization completes correctly 1, otherwise.
- */
-int llc_mac_hdr_init(struct sk_buff *skb,
-		     const unsigned char *sa, const unsigned char *da)
-{
-	int rc = -EINVAL;
-
-	switch (skb->dev->type) {
-	case ARPHRD_ETHER:
-	case ARPHRD_LOOPBACK:
-		rc = dev_hard_header(skb, skb->dev, ETH_P_802_2, da, sa,
-				     skb->len);
-		if (rc > 0)
-			rc = 0;

llc/llc_output.c line 18

Quoted 10 lines
llc/llc_output.c +0 -7
-		break;
-	default:
-		break;
-	}
-	return rc;
-}
-
 /**
  *	llc_build_and_send_ui_pkt - unitdata request interface for upper layers
  *	@sap: sap to use

You may break other uses of LLC.

Why not open code as different function. I used the llc stuff because there were multiple copies of same code (DRY).

maintainer
#2 lore raw
Quoted 16 lines · On Thu, 7 Apr 2022 09:16:40 -0700 Stephen Hemminger wrote:
Quoted 16 lines

I was wondering why the llc code was getting compiled and it turned out to be because I had bridging enabled. It turns out to only needs it for a single function (llc_mac_hdr_init).

net/llc.h +12 -0
+static inline int llc_mac_hdr_init(struct sk_buff *skb,
+				   const unsigned char *sa, const unsigned char *da)
+{
+	int rc = -EINVAL;
+
+	switch (skb->dev->type) {
+	case ARPHRD_ETHER:
+	case ARPHRD_LOOPBACK:
+		rc = dev_hard_header(skb, skb->dev, ETH_P_802_2, da, sa,
+				     skb->len);
+		if (rc > 0)
+			rc = 0;
Quoted 8 lines

net/llc.h extern struct list_head llc_sap_list; · line 131

Quoted 8 lines
net/llc.h +7 -0
+		break;
+	default:
+		break;
+	}
+	return rc;
+}
+

nit: extra new line

Quoted 10 lines
Quoted 10 lines
llc/llc_output.c +0 -10
-int llc_mac_hdr_init(struct sk_buff *skb,
-		     const unsigned char *sa, const unsigned char *da)
-{
-	int rc = -EINVAL;
-
-	switch (skb->dev->type) {
-	case ARPHRD_ETHER:
-	case ARPHRD_LOOPBACK:
-		rc = dev_hard_header(skb, skb->dev, ETH_P_802_2, da, sa,
-				     skb->len);
Quoted 8 lines

llc/llc_output.c line 42

Quoted 8 lines
llc/llc_output.c +0 -8
-		if (rc > 0)
-			rc = 0;
-		break;
-	default:
-		break;
-	}
-	return rc;
-}

There's also an EXPORT somewhere in this file that has to go.

Quoted 8 lines
Quoted 3 lines

/**
* llc_build_and_send_ui_pkt - unitdata request interface for upper layers
* @sap: sap to use

You may break other uses of LLC.

Why not open code as different function. I used the llc stuff because there were multiple copies of same code (DRY).

I didn't quite get what you mean, Stephen, would you mind restating?

#3 lore raw
Quoted 53 lines · On Thu, 7 Apr 2022 19:48:59 -0700 Jakub Kicinski <[email protected]> wrote:
Quoted 16 lines · On Thu, 7 Apr 2022 09:16:40 -0700 Stephen Hemminger wrote:
Quoted 16 lines

I was wondering why the llc code was getting compiled and it turned out to be because I had bridging enabled. It turns out to only needs it for a single function (llc_mac_hdr_init).

net/llc.h +12 -0
+static inline int llc_mac_hdr_init(struct sk_buff *skb,
+				   const unsigned char *sa, const unsigned char *da)
+{
+	int rc = -EINVAL;
+
+	switch (skb->dev->type) {
+	case ARPHRD_ETHER:
+	case ARPHRD_LOOPBACK:
+		rc = dev_hard_header(skb, skb->dev, ETH_P_802_2, da, sa,
+				     skb->len);
+		if (rc > 0)
+			rc = 0;
Quoted 8 lines

net/llc.h extern struct list_head llc_sap_list; · line 131

Quoted 8 lines
net/llc.h +7 -0
+		break;
+	default:
+		break;
+	}
+	return rc;
+}
+

nit: extra new line

Quoted 10 lines
Quoted 10 lines
llc/llc_output.c +0 -10
-int llc_mac_hdr_init(struct sk_buff *skb,
-		     const unsigned char *sa, const unsigned char *da)
-{
-	int rc = -EINVAL;
-
-	switch (skb->dev->type) {
-	case ARPHRD_ETHER:
-	case ARPHRD_LOOPBACK:
-		rc = dev_hard_header(skb, skb->dev, ETH_P_802_2, da, sa,
-				     skb->len);
Quoted 8 lines

llc/llc_output.c line 42

Quoted 8 lines
llc/llc_output.c +0 -8
-		if (rc > 0)
-			rc = 0;
-		break;
-	default:
-		break;
-	}
-	return rc;
-}  

There's also an EXPORT somewhere in this file that has to go.

Quoted 4 lines
Quoted 3 lines

/**
* llc_build_and_send_ui_pkt - unitdata request interface for upper layers
* @sap: sap to use

Quoted 6 lines
Quoted 4 lines

You may break other uses of LLC.

Why not open code as different function. I used the llc stuff because there were multiple copies of same code (DRY).

I didn't quite get what you mean, Stephen, would you mind restating?

Short answer: it was idea that didn't pan out.

Suggestion: get rid of using LLC in bridge and just rewrite that one place.