History

net: set and query VEB/VEPA bridge mode via PF_BRIDGE

Hardware switches may support enabling and disabling the loopback switch which puts the device in a VEPA mode defined in the IEEE 802.1Qbg specification. In this mode frames are not switched in the hardware but sent directly to the switch. SR-IOV capable NICs will likely support this mode I am aware of at least two such devices. Also I am told (but don't have any of this hardware available) that there are devices that only support VEPA modes. In these cases it is important at a minimum to be able to query these attributes. This patch adds an additional IFLA_BRIDGE_MODE attribute that can be set and dumped via the PF_BRIDGE:{SET|GET}LINK operations. Also anticipating bridge attributes that may be common for both embedded bridges and software bridges this adds a flags attribute IFLA_BRIDGE_FLAGS currently used to determine if the command or event is being generated to/from an embedded bridge or software bridge. Finally, the event generation is pulled out of the bridge module and into rtnetlink proper. For example using the macvlan driver in VEPA mode on top of an embedded switch requires putting the embedded switch into a VEPA mode to get the expected results. -------- -------- | VEPA | | VEPA | <-- macvlan vepa edge relays -------- -------- | | | | ------------------ | VEPA | <-- embedded switch in NIC ------------------ | | ------------------- | external switch | <-- shiny new physical ------------------- switch with VEPA support A packet sent from the macvlan VEPA at the top could be loopbacked on the embedded switch and never seen by the external switch. So in order for this to work the embedded switch needs to be set in the VEPA state via the above described commands. By making these attributes nested in IFLA_AF_SPEC we allow future extensions to be made as needed.

John Fastabend committed 14 years ago

Commit 2469ffd1 parent e5a55a84 files · +102 −7Browse files

Unified · Split

4 files
  1. include/uapi/linux/if_bridge.h +18 −0
  2. net/bridge/br_netlink.c +0 −2
  3. net/bridge/br_private.h +3 −1
  4. net/core/rtnetlink.c +81 −4
include/uapi/linux/if_bridge.h+18−0
@@ -97,5 +97,23 @@ struct __fdb_entry { · 96 unmodified lines
9797 __u16 unused;
9898 };
9999
100+/* Bridge Flags */
101+#define BRIDGE_FLAGS_MASTER 1 /* Bridge command to/from master */
102+#define BRIDGE_FLAGS_SELF 2 /* Bridge command to/from lowerdev */
100103
104+#define BRIDGE_MODE_VEB 0 /* Default loopback mode */
105+#define BRIDGE_MODE_VEPA 1 /* 802.1Qbg defined VEPA mode */
106+
107+/* Bridge management nested attributes
108+ * [IFLA_AF_SPEC] = {
109+ * [IFLA_BRIDGE_FLAGS]
110+ * [IFLA_BRIDGE_MODE]
111+ * }
112+ */
113+enum {
114+ IFLA_BRIDGE_FLAGS,
115+ IFLA_BRIDGE_MODE,
116+ __IFLA_BRIDGE_MAX,
117+};
118+#define IFLA_BRIDGE_MAX (__IFLA_BRIDGE_MAX - 1)
101119 #endif /* _UAPI_LINUX_IF_BRIDGE_H */
net/bridge/br_netlink.c+0−2
@@ -166,8 +166,6 @@ int br_setlink(struct net_device *dev, struct nlmsghdr *nlh) · 165 unmodified lines
166166 br_port_state_selection(p->br);
167167 spin_unlock_bh(&p->br->lock);
168168
169− br_ifinfo_notify(RTM_NEWLINK, p);
170−
171169 return 0;
172170 }
173171
net/bridge/br_private.h+3−1
@@ -158,7 +158,9 @@ struct net_bridge_port · 157 unmodified lines
158158
159159 static inline struct net_bridge_port *br_port_get_rcu(const struct net_device *dev)
160160 {
161− struct net_bridge_port *port = rcu_dereference(dev->rx_handler_data);
161+ struct net_bridge_port *port =
162+ rcu_dereference_rtnl(dev->rx_handler_data);
163+
162164 return br_port_exists(dev) ? port : NULL;
163165 }
164166
net/core/rtnetlink.c+81−4
@@ -2295,13 +2295,60 @@ static int rtnl_bridge_getlink(struct sk_buff *skb, struct netlink_callback *cb) · 2294 unmodified lines
22952295 return skb->len;
22962296 }
22972297
2298+static inline size_t bridge_nlmsg_size(void)
2299+{
2300+ return NLMSG_ALIGN(sizeof(struct ifinfomsg))
2301+ + nla_total_size(IFNAMSIZ) /* IFLA_IFNAME */
2302+ + nla_total_size(MAX_ADDR_LEN) /* IFLA_ADDRESS */
2303+ + nla_total_size(sizeof(u32)) /* IFLA_MASTER */
2304+ + nla_total_size(sizeof(u32)) /* IFLA_MTU */
2305+ + nla_total_size(sizeof(u32)) /* IFLA_LINK */
2306+ + nla_total_size(sizeof(u32)) /* IFLA_OPERSTATE */
2307+ + nla_total_size(sizeof(u8)) /* IFLA_PROTINFO */
2308+ + nla_total_size(sizeof(struct nlattr)) /* IFLA_AF_SPEC */
2309+ + nla_total_size(sizeof(u16)) /* IFLA_BRIDGE_FLAGS */
2310+ + nla_total_size(sizeof(u16)); /* IFLA_BRIDGE_MODE */
2311+}
2312+
2313+static int rtnl_bridge_notify(struct net_device *dev, u16 flags)
2314+{
2315+ struct net *net = dev_net(dev);
2316+ struct net_device *master = dev->master;
2317+ struct sk_buff *skb;
2318+ int err = -EOPNOTSUPP;
2319+
2320+ skb = nlmsg_new(bridge_nlmsg_size(), GFP_ATOMIC);
2321+ if (!skb) {
2322+ err = -ENOMEM;
2323+ goto errout;
2324+ }
2325+
2326+ if (!flags && master && master->netdev_ops->ndo_bridge_getlink)
2327+ err = master->netdev_ops->ndo_bridge_getlink(skb, 0, 0, dev);
2328+ else if (dev->netdev_ops->ndo_bridge_getlink)
2329+ err = dev->netdev_ops->ndo_bridge_getlink(skb, 0, 0, dev);
2330+
2331+ if (err < 0)
2332+ goto errout;
2333+
2334+ rtnl_notify(skb, net, 0, RTNLGRP_LINK, NULL, GFP_ATOMIC);
2335+ return 0;
2336+errout:
2337+ WARN_ON(err == -EMSGSIZE);
2338+ kfree_skb(skb);
2339+ rtnl_set_sk_err(net, RTNLGRP_LINK, err);
2340+ return err;
2341+}
2342+
22982343 static int rtnl_bridge_setlink(struct sk_buff *skb, struct nlmsghdr *nlh,
22992344 void *arg)
23002345 {
23012346 struct net *net = sock_net(skb->sk);
23022347 struct ifinfomsg *ifm;
23032348 struct net_device *dev;
2304− int err = -EINVAL;
2349+ struct nlattr *br_spec, *attr = NULL;
2350+ int rem, err = -EOPNOTSUPP;
2351+ u16 flags = 0;
23052352
23062353 if (nlmsg_len(nlh) < sizeof(*ifm))
23072354 return -EINVAL;
@@ -2316,15 +2363,45 @@ static int rtnl_bridge_setlink(struct sk_buff *skb, struct nlmsghdr *nlh, · 8 unmodified lines
23162363 return -ENODEV;
23172364 }
23182365
2319− if (dev->master && dev->master->netdev_ops->ndo_bridge_setlink) {
2366+ br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC);
2367+ if (br_spec) {
2368+ nla_for_each_nested(attr, br_spec, rem) {
2369+ if (nla_type(attr) == IFLA_BRIDGE_FLAGS) {
2370+ flags = nla_get_u16(attr);
2371+ break;
2372+ }
2373+ }
2374+ }
2375+
2376+ if (!flags || (flags & BRIDGE_FLAGS_MASTER)) {
2377+ if (!dev->master ||
2378+ !dev->master->netdev_ops->ndo_bridge_setlink) {
2379+ err = -EOPNOTSUPP;
2380+ goto out;
2381+ }
2382+
23202383 err = dev->master->netdev_ops->ndo_bridge_setlink(dev, nlh);
23212384 if (err)
23222385 goto out;
2386+
2387+ flags &= ~BRIDGE_FLAGS_MASTER;
23232388 }
23242389
2325− if (dev->netdev_ops->ndo_bridge_setlink)
2326− err = dev->netdev_ops->ndo_bridge_setlink(dev, nlh);
2390+ if ((flags & BRIDGE_FLAGS_SELF)) {
2391+ if (!dev->netdev_ops->ndo_bridge_setlink)
2392+ err = -EOPNOTSUPP;
2393+ else
2394+ err = dev->netdev_ops->ndo_bridge_setlink(dev, nlh);
2395+
2396+ if (!err)
2397+ flags &= ~BRIDGE_FLAGS_SELF;
2398+ }
23272399
2400+ if (attr && nla_type(attr) == IFLA_BRIDGE_FLAGS)
2401+ memcpy(nla_data(attr), &flags, sizeof(flags));
2402+ /* Generate event to notify upper layer of bridge change */
2403+ if (!err)
2404+ err = rtnl_bridge_notify(dev, flags);
23282405 out:
23292406 return err;
23302407 }