aboutsummaryrefslogtreecommitdiffstats
path: root/net/bridge
diff options
context:
space:
mode:
Diffstat (limited to 'net/bridge')
-rw-r--r--net/bridge/Makefile2
-rw-r--r--net/bridge/br.c28
-rw-r--r--net/bridge/br_device.c6
-rw-r--r--net/bridge/br_forward.c12
-rw-r--r--net/bridge/br_if.c13
-rw-r--r--net/bridge/br_netfilter.c14
-rw-r--r--net/bridge/br_netlink.c199
-rw-r--r--net/bridge/br_notify.c2
-rw-r--r--net/bridge/br_private.h12
-rw-r--r--net/bridge/br_stp_if.c4
10 files changed, 255 insertions, 37 deletions
diff --git a/net/bridge/Makefile b/net/bridge/Makefile
index 59556e40e143..f444c12cde5a 100644
--- a/net/bridge/Makefile
+++ b/net/bridge/Makefile
@@ -6,7 +6,7 @@ obj-$(CONFIG_BRIDGE) += bridge.o
6 6
7bridge-y := br.o br_device.o br_fdb.o br_forward.o br_if.o br_input.o \ 7bridge-y := br.o br_device.o br_fdb.o br_forward.o br_if.o br_input.o \
8 br_ioctl.o br_notify.o br_stp.o br_stp_bpdu.o \ 8 br_ioctl.o br_notify.o br_stp.o br_stp_bpdu.o \
9 br_stp_if.o br_stp_timer.o 9 br_stp_if.o br_stp_timer.o br_netlink.o
10 10
11bridge-$(CONFIG_SYSFS) += br_sysfs_if.o br_sysfs_br.o 11bridge-$(CONFIG_SYSFS) += br_sysfs_if.o br_sysfs_br.o
12 12
diff --git a/net/bridge/br.c b/net/bridge/br.c
index 12da21afb9ca..654401ceb2db 100644
--- a/net/bridge/br.c
+++ b/net/bridge/br.c
@@ -30,36 +30,46 @@ static struct llc_sap *br_stp_sap;
30 30
31static int __init br_init(void) 31static int __init br_init(void)
32{ 32{
33 int err;
34
33 br_stp_sap = llc_sap_open(LLC_SAP_BSPAN, br_stp_rcv); 35 br_stp_sap = llc_sap_open(LLC_SAP_BSPAN, br_stp_rcv);
34 if (!br_stp_sap) { 36 if (!br_stp_sap) {
35 printk(KERN_ERR "bridge: can't register sap for STP\n"); 37 printk(KERN_ERR "bridge: can't register sap for STP\n");
36 return -EBUSY; 38 return -EADDRINUSE;
37 } 39 }
38 40
39 br_fdb_init(); 41 br_fdb_init();
40 42
41#ifdef CONFIG_BRIDGE_NETFILTER 43 err = br_netfilter_init();
42 if (br_netfilter_init()) 44 if (err)
43 return 1; 45 goto err_out1;
44#endif 46
47 err = register_netdevice_notifier(&br_device_notifier);
48 if (err)
49 goto err_out2;
50
51 br_netlink_init();
45 brioctl_set(br_ioctl_deviceless_stub); 52 brioctl_set(br_ioctl_deviceless_stub);
46 br_handle_frame_hook = br_handle_frame; 53 br_handle_frame_hook = br_handle_frame;
47 54
48 br_fdb_get_hook = br_fdb_get; 55 br_fdb_get_hook = br_fdb_get;
49 br_fdb_put_hook = br_fdb_put; 56 br_fdb_put_hook = br_fdb_put;
50 57
51 register_netdevice_notifier(&br_device_notifier);
52
53 return 0; 58 return 0;
59
60err_out2:
61 br_netfilter_fini();
62err_out1:
63 llc_sap_put(br_stp_sap);
64 return err;
54} 65}
55 66
56static void __exit br_deinit(void) 67static void __exit br_deinit(void)
57{ 68{
58 rcu_assign_pointer(br_stp_sap->rcv_func, NULL); 69 rcu_assign_pointer(br_stp_sap->rcv_func, NULL);
59 70
60#ifdef CONFIG_BRIDGE_NETFILTER 71 br_netlink_fini();
61 br_netfilter_fini(); 72 br_netfilter_fini();
62#endif
63 unregister_netdevice_notifier(&br_device_notifier); 73 unregister_netdevice_notifier(&br_device_notifier);
64 brioctl_set(NULL); 74 brioctl_set(NULL);
65 75
diff --git a/net/bridge/br_device.c b/net/bridge/br_device.c
index 0c88a2ac32c1..2afdc7c0736c 100644
--- a/net/bridge/br_device.c
+++ b/net/bridge/br_device.c
@@ -145,9 +145,9 @@ static int br_set_tx_csum(struct net_device *dev, u32 data)
145 struct net_bridge *br = netdev_priv(dev); 145 struct net_bridge *br = netdev_priv(dev);
146 146
147 if (data) 147 if (data)
148 br->feature_mask |= NETIF_F_IP_CSUM; 148 br->feature_mask |= NETIF_F_NO_CSUM;
149 else 149 else
150 br->feature_mask &= ~NETIF_F_IP_CSUM; 150 br->feature_mask &= ~NETIF_F_ALL_CSUM;
151 151
152 br_features_recompute(br); 152 br_features_recompute(br);
153 return 0; 153 return 0;
@@ -185,5 +185,5 @@ void br_dev_setup(struct net_device *dev)
185 dev->priv_flags = IFF_EBRIDGE; 185 dev->priv_flags = IFF_EBRIDGE;
186 186
187 dev->features = NETIF_F_SG | NETIF_F_FRAGLIST 187 dev->features = NETIF_F_SG | NETIF_F_FRAGLIST
188 | NETIF_F_HIGHDMA | NETIF_F_TSO | NETIF_F_IP_CSUM; 188 | NETIF_F_HIGHDMA | NETIF_F_TSO | NETIF_F_NO_CSUM;
189} 189}
diff --git a/net/bridge/br_forward.c b/net/bridge/br_forward.c
index 56f3aa47e758..0dca027ceb80 100644
--- a/net/bridge/br_forward.c
+++ b/net/bridge/br_forward.c
@@ -20,14 +20,11 @@
20#include <linux/netfilter_bridge.h> 20#include <linux/netfilter_bridge.h>
21#include "br_private.h" 21#include "br_private.h"
22 22
23/* Don't forward packets to originating port or forwarding diasabled */
23static inline int should_deliver(const struct net_bridge_port *p, 24static inline int should_deliver(const struct net_bridge_port *p,
24 const struct sk_buff *skb) 25 const struct sk_buff *skb)
25{ 26{
26 if (skb->dev == p->dev || 27 return (skb->dev != p->dev && p->state == BR_STATE_FORWARDING);
27 p->state != BR_STATE_FORWARDING)
28 return 0;
29
30 return 1;
31} 28}
32 29
33static inline unsigned packet_length(const struct sk_buff *skb) 30static inline unsigned packet_length(const struct sk_buff *skb)
@@ -55,10 +52,9 @@ int br_dev_queue_push_xmit(struct sk_buff *skb)
55 52
56int br_forward_finish(struct sk_buff *skb) 53int br_forward_finish(struct sk_buff *skb)
57{ 54{
58 NF_HOOK(PF_BRIDGE, NF_BR_POST_ROUTING, skb, NULL, skb->dev, 55 return NF_HOOK(PF_BRIDGE, NF_BR_POST_ROUTING, skb, NULL, skb->dev,
59 br_dev_queue_push_xmit); 56 br_dev_queue_push_xmit);
60 57
61 return 0;
62} 58}
63 59
64static void __br_deliver(const struct net_bridge_port *to, struct sk_buff *skb) 60static void __br_deliver(const struct net_bridge_port *to, struct sk_buff *skb)
diff --git a/net/bridge/br_if.c b/net/bridge/br_if.c
index f5d47bf4f967..fdec773f5b52 100644
--- a/net/bridge/br_if.c
+++ b/net/bridge/br_if.c
@@ -372,12 +372,17 @@ void br_features_recompute(struct net_bridge *br)
372 struct net_bridge_port *p; 372 struct net_bridge_port *p;
373 unsigned long features, checksum; 373 unsigned long features, checksum;
374 374
375 features = br->feature_mask &~ NETIF_F_IP_CSUM; 375 checksum = br->feature_mask & NETIF_F_ALL_CSUM ? NETIF_F_NO_CSUM : 0;
376 checksum = br->feature_mask & NETIF_F_IP_CSUM; 376 features = br->feature_mask & ~NETIF_F_ALL_CSUM;
377 377
378 list_for_each_entry(p, &br->port_list, list) { 378 list_for_each_entry(p, &br->port_list, list) {
379 if (!(p->dev->features 379 if (checksum & NETIF_F_NO_CSUM &&
380 & (NETIF_F_IP_CSUM|NETIF_F_NO_CSUM|NETIF_F_HW_CSUM))) 380 !(p->dev->features & NETIF_F_NO_CSUM))
381 checksum ^= NETIF_F_NO_CSUM | NETIF_F_HW_CSUM;
382 if (checksum & NETIF_F_HW_CSUM &&
383 !(p->dev->features & NETIF_F_HW_CSUM))
384 checksum ^= NETIF_F_HW_CSUM | NETIF_F_IP_CSUM;
385 if (!(p->dev->features & NETIF_F_IP_CSUM))
381 checksum = 0; 386 checksum = 0;
382 features &= p->dev->features; 387 features &= p->dev->features;
383 } 388 }
diff --git a/net/bridge/br_netfilter.c b/net/bridge/br_netfilter.c
index 3da9264449f7..3e41f9d6d51c 100644
--- a/net/bridge/br_netfilter.c
+++ b/net/bridge/br_netfilter.c
@@ -407,12 +407,8 @@ static unsigned int br_nf_pre_routing_ipv6(unsigned int hook,
407 if (pkt_len || hdr->nexthdr != NEXTHDR_HOP) { 407 if (pkt_len || hdr->nexthdr != NEXTHDR_HOP) {
408 if (pkt_len + sizeof(struct ipv6hdr) > skb->len) 408 if (pkt_len + sizeof(struct ipv6hdr) > skb->len)
409 goto inhdr_error; 409 goto inhdr_error;
410 if (pkt_len + sizeof(struct ipv6hdr) < skb->len) { 410 if (pskb_trim_rcsum(skb, pkt_len + sizeof(struct ipv6hdr)))
411 if (__pskb_trim(skb, pkt_len + sizeof(struct ipv6hdr))) 411 goto inhdr_error;
412 goto inhdr_error;
413 if (skb->ip_summed == CHECKSUM_HW)
414 skb->ip_summed = CHECKSUM_NONE;
415 }
416 } 412 }
417 if (hdr->nexthdr == NEXTHDR_HOP && check_hbh_len(skb)) 413 if (hdr->nexthdr == NEXTHDR_HOP && check_hbh_len(skb))
418 goto inhdr_error; 414 goto inhdr_error;
@@ -495,11 +491,7 @@ static unsigned int br_nf_pre_routing(unsigned int hook, struct sk_buff **pskb,
495 if (skb->len < len || len < 4 * iph->ihl) 491 if (skb->len < len || len < 4 * iph->ihl)
496 goto inhdr_error; 492 goto inhdr_error;
497 493
498 if (skb->len > len) { 494 pskb_trim_rcsum(skb, len);
499 __pskb_trim(skb, len);
500 if (skb->ip_summed == CHECKSUM_HW)
501 skb->ip_summed = CHECKSUM_NONE;
502 }
503 495
504 nf_bridge_put(skb->nf_bridge); 496 nf_bridge_put(skb->nf_bridge);
505 if (!nf_bridge_alloc(skb)) 497 if (!nf_bridge_alloc(skb))
diff --git a/net/bridge/br_netlink.c b/net/bridge/br_netlink.c
new file mode 100644
index 000000000000..881d7d1a732a
--- /dev/null
+++ b/net/bridge/br_netlink.c
@@ -0,0 +1,199 @@
1/*
2 * Bridge netlink control interface
3 *
4 * Authors:
5 * Stephen Hemminger <shemminger@osdl.org>
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version
10 * 2 of the License, or (at your option) any later version.
11 */
12
13#include <linux/kernel.h>
14#include <linux/rtnetlink.h>
15#include "br_private.h"
16
17/*
18 * Create one netlink message for one interface
19 * Contains port and master info as well as carrier and bridge state.
20 */
21static int br_fill_ifinfo(struct sk_buff *skb, const struct net_bridge_port *port,
22 u32 pid, u32 seq, int event, unsigned int flags)
23{
24 const struct net_bridge *br = port->br;
25 const struct net_device *dev = port->dev;
26 struct ifinfomsg *r;
27 struct nlmsghdr *nlh;
28 unsigned char *b = skb->tail;
29 u32 mtu = dev->mtu;
30 u8 operstate = netif_running(dev) ? dev->operstate : IF_OPER_DOWN;
31 u8 portstate = port->state;
32
33 pr_debug("br_fill_info event %d port %s master %s\n",
34 event, dev->name, br->dev->name);
35
36 nlh = NLMSG_NEW(skb, pid, seq, event, sizeof(*r), flags);
37 r = NLMSG_DATA(nlh);
38 r->ifi_family = AF_BRIDGE;
39 r->__ifi_pad = 0;
40 r->ifi_type = dev->type;
41 r->ifi_index = dev->ifindex;
42 r->ifi_flags = dev_get_flags(dev);
43 r->ifi_change = 0;
44
45 RTA_PUT(skb, IFLA_IFNAME, strlen(dev->name)+1, dev->name);
46
47 RTA_PUT(skb, IFLA_MASTER, sizeof(int), &br->dev->ifindex);
48
49 if (dev->addr_len)
50 RTA_PUT(skb, IFLA_ADDRESS, dev->addr_len, dev->dev_addr);
51
52 RTA_PUT(skb, IFLA_MTU, sizeof(mtu), &mtu);
53 if (dev->ifindex != dev->iflink)
54 RTA_PUT(skb, IFLA_LINK, sizeof(int), &dev->iflink);
55
56
57 RTA_PUT(skb, IFLA_OPERSTATE, sizeof(operstate), &operstate);
58
59 if (event == RTM_NEWLINK)
60 RTA_PUT(skb, IFLA_PROTINFO, sizeof(portstate), &portstate);
61
62 nlh->nlmsg_len = skb->tail - b;
63
64 return skb->len;
65
66nlmsg_failure:
67rtattr_failure:
68
69 skb_trim(skb, b - skb->data);
70 return -EINVAL;
71}
72
73/*
74 * Notify listeners of a change in port information
75 */
76void br_ifinfo_notify(int event, struct net_bridge_port *port)
77{
78 struct sk_buff *skb;
79 int err = -ENOMEM;
80
81 pr_debug("bridge notify event=%d\n", event);
82 skb = alloc_skb(NLMSG_SPACE(sizeof(struct ifinfomsg) + 128),
83 GFP_ATOMIC);
84 if (!skb)
85 goto err_out;
86
87 err = br_fill_ifinfo(skb, port, current->pid, 0, event, 0);
88 if (err)
89 goto err_kfree;
90
91 NETLINK_CB(skb).dst_group = RTNLGRP_LINK;
92 netlink_broadcast(rtnl, skb, 0, RTNLGRP_LINK, GFP_ATOMIC);
93 return;
94
95err_kfree:
96 kfree_skb(skb);
97err_out:
98 netlink_set_err(rtnl, 0, RTNLGRP_LINK, err);
99}
100
101/*
102 * Dump information about all ports, in response to GETLINK
103 */
104static int br_dump_ifinfo(struct sk_buff *skb, struct netlink_callback *cb)
105{
106 struct net_device *dev;
107 int idx;
108 int s_idx = cb->args[0];
109 int err = 0;
110
111 read_lock(&dev_base_lock);
112 for (dev = dev_base, idx = 0; dev; dev = dev->next) {
113 struct net_bridge_port *p = dev->br_port;
114
115 /* not a bridge port */
116 if (!p)
117 continue;
118
119 if (idx < s_idx)
120 continue;
121
122 err = br_fill_ifinfo(skb, p, NETLINK_CB(cb->skb).pid,
123 cb->nlh->nlmsg_seq, RTM_NEWLINK, NLM_F_MULTI);
124 if (err <= 0)
125 break;
126 ++idx;
127 }
128 read_unlock(&dev_base_lock);
129
130 cb->args[0] = idx;
131
132 return skb->len;
133}
134
135/*
136 * Change state of port (ie from forwarding to blocking etc)
137 * Used by spanning tree in user space.
138 */
139static int br_rtm_setlink(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
140{
141 struct rtattr **rta = arg;
142 struct ifinfomsg *ifm = NLMSG_DATA(nlh);
143 struct net_device *dev;
144 struct net_bridge_port *p;
145 u8 new_state;
146
147 if (ifm->ifi_family != AF_BRIDGE)
148 return -EPFNOSUPPORT;
149
150 /* Must pass valid state as PROTINFO */
151 if (rta[IFLA_PROTINFO-1]) {
152 u8 *pstate = RTA_DATA(rta[IFLA_PROTINFO-1]);
153 new_state = *pstate;
154 } else
155 return -EINVAL;
156
157 if (new_state > BR_STATE_BLOCKING)
158 return -EINVAL;
159
160 /* Find bridge port */
161 dev = __dev_get_by_index(ifm->ifi_index);
162 if (!dev)
163 return -ENODEV;
164
165 p = dev->br_port;
166 if (!p)
167 return -EINVAL;
168
169 /* if kernel STP is running, don't allow changes */
170 if (p->br->stp_enabled)
171 return -EBUSY;
172
173 if (!netif_running(dev))
174 return -ENETDOWN;
175
176 if (!netif_carrier_ok(dev) && new_state != BR_STATE_DISABLED)
177 return -ENETDOWN;
178
179 p->state = new_state;
180 br_log_state(p);
181 return 0;
182}
183
184
185static struct rtnetlink_link bridge_rtnetlink_table[RTM_NR_MSGTYPES] = {
186 [RTM_GETLINK - RTM_BASE] = { .dumpit = br_dump_ifinfo, },
187 [RTM_SETLINK - RTM_BASE] = { .doit = br_rtm_setlink, },
188};
189
190void __init br_netlink_init(void)
191{
192 rtnetlink_links[PF_BRIDGE] = bridge_rtnetlink_table;
193}
194
195void __exit br_netlink_fini(void)
196{
197 rtnetlink_links[PF_BRIDGE] = NULL;
198}
199
diff --git a/net/bridge/br_notify.c b/net/bridge/br_notify.c
index a43a9c1d50d7..20278494e4da 100644
--- a/net/bridge/br_notify.c
+++ b/net/bridge/br_notify.c
@@ -14,6 +14,7 @@
14 */ 14 */
15 15
16#include <linux/kernel.h> 16#include <linux/kernel.h>
17#include <linux/rtnetlink.h>
17 18
18#include "br_private.h" 19#include "br_private.h"
19 20
@@ -49,6 +50,7 @@ static int br_device_event(struct notifier_block *unused, unsigned long event, v
49 50
50 case NETDEV_CHANGEADDR: 51 case NETDEV_CHANGEADDR:
51 br_fdb_changeaddr(p, dev->dev_addr); 52 br_fdb_changeaddr(p, dev->dev_addr);
53 br_ifinfo_notify(RTM_NEWLINK, p);
52 br_stp_recalculate_bridge_id(br); 54 br_stp_recalculate_bridge_id(br);
53 break; 55 break;
54 56
diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h
index 86ecea7ed372..c491fb2f280e 100644
--- a/net/bridge/br_private.h
+++ b/net/bridge/br_private.h
@@ -29,7 +29,7 @@
29 29
30#define BR_PORT_DEBOUNCE (HZ/10) 30#define BR_PORT_DEBOUNCE (HZ/10)
31 31
32#define BR_VERSION "2.1" 32#define BR_VERSION "2.2"
33 33
34typedef struct bridge_id bridge_id; 34typedef struct bridge_id bridge_id;
35typedef struct mac_addr mac_addr; 35typedef struct mac_addr mac_addr;
@@ -192,8 +192,13 @@ extern int br_dev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
192extern int br_ioctl_deviceless_stub(unsigned int cmd, void __user *arg); 192extern int br_ioctl_deviceless_stub(unsigned int cmd, void __user *arg);
193 193
194/* br_netfilter.c */ 194/* br_netfilter.c */
195#ifdef CONFIG_BRIDGE_NETFILTER
195extern int br_netfilter_init(void); 196extern int br_netfilter_init(void);
196extern void br_netfilter_fini(void); 197extern void br_netfilter_fini(void);
198#else
199#define br_netfilter_init() (0)
200#define br_netfilter_fini() do { } while(0)
201#endif
197 202
198/* br_stp.c */ 203/* br_stp.c */
199extern void br_log_state(const struct net_bridge_port *p); 204extern void br_log_state(const struct net_bridge_port *p);
@@ -232,6 +237,11 @@ extern struct net_bridge_fdb_entry *(*br_fdb_get_hook)(struct net_bridge *br,
232extern void (*br_fdb_put_hook)(struct net_bridge_fdb_entry *ent); 237extern void (*br_fdb_put_hook)(struct net_bridge_fdb_entry *ent);
233 238
234 239
240/* br_netlink.c */
241extern void br_netlink_init(void);
242extern void br_netlink_fini(void);
243extern void br_ifinfo_notify(int event, struct net_bridge_port *port);
244
235#ifdef CONFIG_SYSFS 245#ifdef CONFIG_SYSFS
236/* br_sysfs_if.c */ 246/* br_sysfs_if.c */
237extern struct sysfs_ops brport_sysfs_ops; 247extern struct sysfs_ops brport_sysfs_ops;
diff --git a/net/bridge/br_stp_if.c b/net/bridge/br_stp_if.c
index 23dea1422c9a..14cd025079af 100644
--- a/net/bridge/br_stp_if.c
+++ b/net/bridge/br_stp_if.c
@@ -16,6 +16,7 @@
16#include <linux/kernel.h> 16#include <linux/kernel.h>
17#include <linux/smp_lock.h> 17#include <linux/smp_lock.h>
18#include <linux/etherdevice.h> 18#include <linux/etherdevice.h>
19#include <linux/rtnetlink.h>
19 20
20#include "br_private.h" 21#include "br_private.h"
21#include "br_private_stp.h" 22#include "br_private_stp.h"
@@ -86,6 +87,7 @@ void br_stp_disable_bridge(struct net_bridge *br)
86void br_stp_enable_port(struct net_bridge_port *p) 87void br_stp_enable_port(struct net_bridge_port *p)
87{ 88{
88 br_init_port(p); 89 br_init_port(p);
90 br_ifinfo_notify(RTM_NEWLINK, p);
89 br_port_state_selection(p->br); 91 br_port_state_selection(p->br);
90} 92}
91 93
@@ -99,6 +101,8 @@ void br_stp_disable_port(struct net_bridge_port *p)
99 printk(KERN_INFO "%s: port %i(%s) entering %s state\n", 101 printk(KERN_INFO "%s: port %i(%s) entering %s state\n",
100 br->dev->name, p->port_no, p->dev->name, "disabled"); 102 br->dev->name, p->port_no, p->dev->name, "disabled");
101 103
104 br_ifinfo_notify(RTM_DELLINK, p);
105
102 wasroot = br_is_root_bridge(br); 106 wasroot = br_is_root_bridge(br);
103 br_become_designated_port(p); 107 br_become_designated_port(p);
104 p->state = BR_STATE_DISABLED; 108 p->state = BR_STATE_DISABLED;