History

mpls: Multicast route table change notifications

Unlike IPv4 this code notifies on all cases where mpls routes are added or removed and it never automatically removes routes. Avoiding both the userspace confusion that is caused by omitting route updates and the possibility of a flood of netlink traffic when an interface goes doew. For now reserved labels are handled automatically and userspace is not notified.

Eric W. Biederman committed 11 years ago

Commit 8de147d1 parent 03c05662 files · +62 −0Browse files

Unified · Split

2 files
  1. include/uapi/linux/rtnetlink.h +2 −0
  2. net/mpls/af_mpls.c +60 −0
include/uapi/linux/rtnetlink.h+2−0
@@ -631,6 +631,8 @@ enum rtnetlink_groups { · 630 unmodified lines
631631 #define RTNLGRP_IPV6_NETCONF RTNLGRP_IPV6_NETCONF
632632 RTNLGRP_MDB,
633633 #define RTNLGRP_MDB RTNLGRP_MDB
634+ RTNLGRP_MPLS_ROUTE,
635+#define RTNLGRP_MPLS_ROUTE RTNLGRP_MPLS_ROUTE
634636 __RTNLGRP_MAX
635637 };
636638 #define RTNLGRP_MAX (__RTNLGRP_MAX - 1)
net/mpls/af_mpls.c+60−0
@@ -36,6 +36,10 @@ struct mpls_route { /* next hop label forwarding entry */ · 35 unmodified lines
3636 static int zero = 0;
3737 static int label_limit = (1 << 20) - 1;
3838
39+static void rtmsg_lfib(int event, u32 label, struct mpls_route *rt,
40+ struct nlmsghdr *nlh, struct net *net, u32 portid,
41+ unsigned int nlm_flags);
42+
3943 static struct mpls_route *mpls_route_input_rcu(struct net *net, unsigned index)
4044 {
4145 struct mpls_route *rt = NULL;
@@ -246,6 +250,20 @@ static void mpls_rt_free(struct mpls_route *rt) · 204 unmodified lines
246250 kfree_rcu(rt, rt_rcu);
247251 }
248252
253+static void mpls_notify_route(struct net *net, unsigned index,
254+ struct mpls_route *old, struct mpls_route *new,
255+ const struct nl_info *info)
256+{
257+ struct nlmsghdr *nlh = info ? info->nlh : NULL;
258+ unsigned portid = info ? info->portid : 0;
259+ int event = new ? RTM_NEWROUTE : RTM_DELROUTE;
260+ struct mpls_route *rt = new ? new : old;
261+ unsigned nlm_flags = (old && new) ? NLM_F_REPLACE : 0;
262+ /* Ignore reserved labels for now */
263+ if (rt && (index >= 16))
264+ rtmsg_lfib(event, index, rt, nlh, net, portid, nlm_flags);
265+}
266+
249267 static void mpls_route_update(struct net *net, unsigned index,
250268 struct net_device *dev, struct mpls_route *new,
251269 const struct nl_info *info)
@@ -260,6 +278,8 @@ static void mpls_route_update(struct net *net, unsigned index, · 8 unmodified lines
260278 old = rt;
261279 }
262280
281+ mpls_notify_route(net, index, old, new, info);
282+
263283 /* If we removed a route free it now */
264284 mpls_rt_free(old);
265285 }
@@ -692,6 +712,46 @@ static int mpls_dump_routes(struct sk_buff *skb, struct netlink_callback *cb) · 426 unmodified lines
692712 return skb->len;
693713 }
694714
715+static inline size_t lfib_nlmsg_size(struct mpls_route *rt)
716+{
717+ size_t payload =
718+ NLMSG_ALIGN(sizeof(struct rtmsg))
719+ + nla_total_size(2 + rt->rt_via_alen) /* RTA_VIA */
720+ + nla_total_size(4); /* RTA_DST */
721+ if (rt->rt_labels) /* RTA_NEWDST */
722+ payload += nla_total_size(rt->rt_labels * 4);
723+ if (rt->rt_dev) /* RTA_OIF */
724+ payload += nla_total_size(4);
725+ return payload;
726+}
727+
728+static void rtmsg_lfib(int event, u32 label, struct mpls_route *rt,
729+ struct nlmsghdr *nlh, struct net *net, u32 portid,
730+ unsigned int nlm_flags)
731+{
732+ struct sk_buff *skb;
733+ u32 seq = nlh ? nlh->nlmsg_seq : 0;
734+ int err = -ENOBUFS;
735+
736+ skb = nlmsg_new(lfib_nlmsg_size(rt), GFP_KERNEL);
737+ if (skb == NULL)
738+ goto errout;
739+
740+ err = mpls_dump_route(skb, portid, seq, event, label, rt, nlm_flags);
741+ if (err < 0) {
742+ /* -EMSGSIZE implies BUG in lfib_nlmsg_size */
743+ WARN_ON(err == -EMSGSIZE);
744+ kfree_skb(skb);
745+ goto errout;
746+ }
747+ rtnl_notify(skb, net, portid, RTNLGRP_MPLS_ROUTE, nlh, GFP_KERNEL);
748+
749+ return;
750+errout:
751+ if (err < 0)
752+ rtnl_set_sk_err(net, RTNLGRP_MPLS_ROUTE, err);
753+}
754+
695755 static int resize_platform_label_table(struct net *net, size_t limit)
696756 {
697757 size_t size = sizeof(struct mpls_route *) * limit;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t