1 #include <linux/types.h>
2 #include <linux/skbuff.h>
3 #include <linux/socket.h>
4 #include <linux/sysctl.h>
6 #include <linux/module.h>
7 #include <linux/if_arp.h>
8 #include <linux/ipv6.h>
9 #include <linux/mpls.h>
10 #include <linux/vmalloc.h>
15 #include <net/ip_fib.h>
16 #include <net/netevent.h>
17 #include <net/netns/generic.h>
20 #define LABEL_NOT_SPECIFIED (1<<20)
21 #define MAX_NEW_LABELS 2
23 /* This maximum ha length copied from the definition of struct neighbour */
24 #define MAX_VIA_ALEN (ALIGN(MAX_ADDR_LEN, sizeof(unsigned long)))
26 struct mpls_route { /* next hop label forwarding entry */
27 struct net_device __rcu *rt_dev;
28 struct rcu_head rt_rcu;
29 u32 rt_label[MAX_NEW_LABELS];
30 u8 rt_protocol; /* routing protocol that set this entry */
38 static int label_limit = (1 << 20) - 1;
40 static void rtmsg_lfib(int event, u32 label, struct mpls_route *rt,
41 struct nlmsghdr *nlh, struct net *net, u32 portid,
42 unsigned int nlm_flags);
44 static struct mpls_route *mpls_route_input_rcu(struct net *net, unsigned index)
46 struct mpls_route *rt = NULL;
48 if (index < net->mpls.platform_labels) {
49 struct mpls_route __rcu **platform_label =
50 rcu_dereference(net->mpls.platform_label);
51 rt = rcu_dereference(platform_label[index]);
56 static bool mpls_output_possible(const struct net_device *dev)
58 return dev && (dev->flags & IFF_UP) && netif_carrier_ok(dev);
61 static unsigned int mpls_rt_header_size(const struct mpls_route *rt)
63 /* The size of the layer 2.5 labels to be added for this route */
64 return rt->rt_labels * sizeof(struct mpls_shim_hdr);
67 static unsigned int mpls_dev_mtu(const struct net_device *dev)
69 /* The amount of data the layer 2 frame can hold */
73 static bool mpls_pkt_too_big(const struct sk_buff *skb, unsigned int mtu)
78 if (skb_is_gso(skb) && skb_gso_network_seglen(skb) <= mtu)
84 static bool mpls_egress(struct mpls_route *rt, struct sk_buff *skb,
85 struct mpls_entry_decoded dec)
87 /* RFC4385 and RFC5586 encode other packets in mpls such that
88 * they don't conflict with the ip version number, making
89 * decoding by examining the ip version correct in everything
90 * except for the strangest cases.
92 * The strange cases if we choose to support them will require
93 * manual configuration.
98 /* The IPv4 code below accesses through the IPv4 header
99 * checksum, which is 12 bytes into the packet.
100 * The IPv6 code below accesses through the IPv6 hop limit
101 * which is 8 bytes into the packet.
103 * For all supported cases there should always be at least 12
104 * bytes of packet data present. The IPv4 header is 20 bytes
105 * without options and the IPv6 header is always 40 bytes
108 if (!pskb_may_pull(skb, 12))
111 /* Use ip_hdr to find the ip protocol version */
113 if (hdr4->version == 4) {
114 skb->protocol = htons(ETH_P_IP);
115 csum_replace2(&hdr4->check,
116 htons(hdr4->ttl << 8),
117 htons(dec.ttl << 8));
120 else if (hdr4->version == 6) {
121 struct ipv6hdr *hdr6 = ipv6_hdr(skb);
122 skb->protocol = htons(ETH_P_IPV6);
123 hdr6->hop_limit = dec.ttl;
126 /* version 0 and version 1 are used by pseudo wires */
131 static int mpls_forward(struct sk_buff *skb, struct net_device *dev,
132 struct packet_type *pt, struct net_device *orig_dev)
134 struct net *net = dev_net(dev);
135 struct mpls_shim_hdr *hdr;
136 struct mpls_route *rt;
137 struct mpls_entry_decoded dec;
138 struct net_device *out_dev;
140 unsigned int new_header_size;
144 /* Careful this entire function runs inside of an rcu critical section */
146 if (skb->pkt_type != PACKET_HOST)
149 if ((skb = skb_share_check(skb, GFP_ATOMIC)) == NULL)
152 if (!pskb_may_pull(skb, sizeof(*hdr)))
155 /* Read and decode the label */
157 dec = mpls_entry_decode(hdr);
160 skb_pull(skb, sizeof(*hdr));
161 skb_reset_network_header(skb);
165 rt = mpls_route_input_rcu(net, dec.label);
169 /* Find the output device */
170 out_dev = rcu_dereference(rt->rt_dev);
171 if (!mpls_output_possible(out_dev))
174 if (skb_warn_if_lro(skb))
177 skb_forward_csum(skb);
179 /* Verify ttl is valid */
184 /* Verify the destination can hold the packet */
185 new_header_size = mpls_rt_header_size(rt);
186 mtu = mpls_dev_mtu(out_dev);
187 if (mpls_pkt_too_big(skb, mtu - new_header_size))
190 hh_len = LL_RESERVED_SPACE(out_dev);
191 if (!out_dev->header_ops)
194 /* Ensure there is enough space for the headers in the skb */
195 if (skb_cow(skb, hh_len + new_header_size))
199 skb->protocol = htons(ETH_P_MPLS_UC);
201 if (unlikely(!new_header_size && dec.bos)) {
202 /* Penultimate hop popping */
203 if (!mpls_egress(rt, skb, dec))
208 skb_push(skb, new_header_size);
209 skb_reset_network_header(skb);
210 /* Push the new labels */
213 for (i = rt->rt_labels - 1; i >= 0; i--) {
214 hdr[i] = mpls_entry_encode(rt->rt_label[i], dec.ttl, 0, bos);
219 err = neigh_xmit(rt->rt_via_table, out_dev, rt->rt_via, skb);
221 net_dbg_ratelimited("%s: packet transmission failed: %d\n",
230 static struct packet_type mpls_packet_type __read_mostly = {
231 .type = cpu_to_be16(ETH_P_MPLS_UC),
232 .func = mpls_forward,
235 static const struct nla_policy rtm_mpls_policy[RTA_MAX+1] = {
236 [RTA_DST] = { .type = NLA_U32 },
237 [RTA_OIF] = { .type = NLA_U32 },
240 struct mpls_route_config {
245 u8 rc_via[MAX_VIA_ALEN];
247 u32 rc_output_labels;
248 u32 rc_output_label[MAX_NEW_LABELS];
250 struct nl_info rc_nlinfo;
253 static struct mpls_route *mpls_rt_alloc(size_t alen)
255 struct mpls_route *rt;
257 rt = kzalloc(sizeof(*rt) + alen, GFP_KERNEL);
259 rt->rt_via_alen = alen;
263 static void mpls_rt_free(struct mpls_route *rt)
266 kfree_rcu(rt, rt_rcu);
269 static void mpls_notify_route(struct net *net, unsigned index,
270 struct mpls_route *old, struct mpls_route *new,
271 const struct nl_info *info)
273 struct nlmsghdr *nlh = info ? info->nlh : NULL;
274 unsigned portid = info ? info->portid : 0;
275 int event = new ? RTM_NEWROUTE : RTM_DELROUTE;
276 struct mpls_route *rt = new ? new : old;
277 unsigned nlm_flags = (old && new) ? NLM_F_REPLACE : 0;
278 /* Ignore reserved labels for now */
279 if (rt && (index >= 16))
280 rtmsg_lfib(event, index, rt, nlh, net, portid, nlm_flags);
283 static void mpls_route_update(struct net *net, unsigned index,
284 struct net_device *dev, struct mpls_route *new,
285 const struct nl_info *info)
287 struct mpls_route __rcu **platform_label;
288 struct mpls_route *rt, *old = NULL;
292 platform_label = rtnl_dereference(net->mpls.platform_label);
293 rt = rtnl_dereference(platform_label[index]);
294 if (!dev || (rt && (rtnl_dereference(rt->rt_dev) == dev))) {
295 rcu_assign_pointer(platform_label[index], new);
299 mpls_notify_route(net, index, old, new, info);
301 /* If we removed a route free it now */
305 static unsigned find_free_label(struct net *net)
307 struct mpls_route __rcu **platform_label;
308 size_t platform_labels;
311 platform_label = rtnl_dereference(net->mpls.platform_label);
312 platform_labels = net->mpls.platform_labels;
313 for (index = 16; index < platform_labels; index++) {
314 if (!rtnl_dereference(platform_label[index]))
317 return LABEL_NOT_SPECIFIED;
320 static int mpls_route_add(struct mpls_route_config *cfg)
322 struct mpls_route __rcu **platform_label;
323 struct net *net = cfg->rc_nlinfo.nl_net;
324 struct net_device *dev = NULL;
325 struct mpls_route *rt, *old;
330 index = cfg->rc_label;
332 /* If a label was not specified during insert pick one */
333 if ((index == LABEL_NOT_SPECIFIED) &&
334 (cfg->rc_nlflags & NLM_F_CREATE)) {
335 index = find_free_label(net);
338 /* The first 16 labels are reserved, and may not be set */
342 /* The full 20 bit range may not be supported. */
343 if (index >= net->mpls.platform_labels)
346 /* Ensure only a supported number of labels are present */
347 if (cfg->rc_output_labels > MAX_NEW_LABELS)
351 dev = dev_get_by_index(net, cfg->rc_ifindex);
355 /* For now just support ethernet devices */
357 if ((dev->type != ARPHRD_ETHER) && (dev->type != ARPHRD_LOOPBACK))
361 if ((cfg->rc_via_table == NEIGH_LINK_TABLE) &&
362 (dev->addr_len != cfg->rc_via_alen))
365 /* Append makes no sense with mpls */
367 if (cfg->rc_nlflags & NLM_F_APPEND)
371 platform_label = rtnl_dereference(net->mpls.platform_label);
372 old = rtnl_dereference(platform_label[index]);
373 if ((cfg->rc_nlflags & NLM_F_EXCL) && old)
377 if (!(cfg->rc_nlflags & NLM_F_REPLACE) && old)
381 if (!(cfg->rc_nlflags & NLM_F_CREATE) && !old)
385 rt = mpls_rt_alloc(cfg->rc_via_alen);
389 rt->rt_labels = cfg->rc_output_labels;
390 for (i = 0; i < rt->rt_labels; i++)
391 rt->rt_label[i] = cfg->rc_output_label[i];
392 rt->rt_protocol = cfg->rc_protocol;
393 RCU_INIT_POINTER(rt->rt_dev, dev);
394 rt->rt_via_table = cfg->rc_via_table;
395 memcpy(rt->rt_via, cfg->rc_via, cfg->rc_via_alen);
397 mpls_route_update(net, index, NULL, rt, &cfg->rc_nlinfo);
408 static int mpls_route_del(struct mpls_route_config *cfg)
410 struct net *net = cfg->rc_nlinfo.nl_net;
414 index = cfg->rc_label;
416 /* The first 16 labels are reserved, and may not be removed */
420 /* The full 20 bit range may not be supported */
421 if (index >= net->mpls.platform_labels)
424 mpls_route_update(net, index, NULL, NULL, &cfg->rc_nlinfo);
431 static void mpls_ifdown(struct net_device *dev)
433 struct mpls_route __rcu **platform_label;
434 struct net *net = dev_net(dev);
437 platform_label = rtnl_dereference(net->mpls.platform_label);
438 for (index = 0; index < net->mpls.platform_labels; index++) {
439 struct mpls_route *rt = rtnl_dereference(platform_label[index]);
442 if (rtnl_dereference(rt->rt_dev) != dev)
448 static int mpls_dev_notify(struct notifier_block *this, unsigned long event,
451 struct net_device *dev = netdev_notifier_info_to_dev(ptr);
454 case NETDEV_UNREGISTER:
461 static struct notifier_block mpls_dev_notifier = {
462 .notifier_call = mpls_dev_notify,
465 static int nla_put_via(struct sk_buff *skb,
466 u8 table, const void *addr, int alen)
468 static const int table_to_family[NEIGH_NR_TABLES + 1] = {
469 AF_INET, AF_INET6, AF_DECnet, AF_PACKET,
473 int family = AF_UNSPEC;
475 nla = nla_reserve(skb, RTA_VIA, alen + 2);
479 if (table <= NEIGH_NR_TABLES)
480 family = table_to_family[table];
483 via->rtvia_family = family;
484 memcpy(via->rtvia_addr, addr, alen);
488 int nla_put_labels(struct sk_buff *skb, int attrtype,
489 u8 labels, const u32 label[])
492 struct mpls_shim_hdr *nla_label;
495 nla = nla_reserve(skb, attrtype, labels*4);
499 nla_label = nla_data(nla);
501 for (i = labels - 1; i >= 0; i--) {
502 nla_label[i] = mpls_entry_encode(label[i], 0, 0, bos);
509 int nla_get_labels(const struct nlattr *nla,
510 u32 max_labels, u32 *labels, u32 label[])
512 unsigned len = nla_len(nla);
514 struct mpls_shim_hdr *nla_label;
518 /* len needs to be an even multiple of 4 (the label size) */
522 /* Limit the number of new labels allowed */
524 if (nla_labels > max_labels)
527 nla_label = nla_data(nla);
529 for (i = nla_labels - 1; i >= 0; i--, bos = false) {
530 struct mpls_entry_decoded dec;
531 dec = mpls_entry_decode(nla_label + i);
533 /* Ensure the bottom of stack flag is properly set
534 * and ttl and tc are both clear.
536 if ((dec.bos != bos) || dec.ttl || dec.tc)
539 label[i] = dec.label;
541 *labels = nla_labels;
545 static int rtm_to_route_config(struct sk_buff *skb, struct nlmsghdr *nlh,
546 struct mpls_route_config *cfg)
549 struct nlattr *tb[RTA_MAX+1];
553 err = nlmsg_parse(nlh, sizeof(*rtm), tb, RTA_MAX, rtm_mpls_policy);
558 rtm = nlmsg_data(nlh);
559 memset(cfg, 0, sizeof(*cfg));
561 if (rtm->rtm_family != AF_MPLS)
563 if (rtm->rtm_dst_len != 20)
565 if (rtm->rtm_src_len != 0)
567 if (rtm->rtm_tos != 0)
569 if (rtm->rtm_table != RT_TABLE_MAIN)
571 /* Any value is acceptable for rtm_protocol */
573 /* As mpls uses destination specific addresses
574 * (or source specific address in the case of multicast)
575 * all addresses have universal scope.
577 if (rtm->rtm_scope != RT_SCOPE_UNIVERSE)
579 if (rtm->rtm_type != RTN_UNICAST)
581 if (rtm->rtm_flags != 0)
584 cfg->rc_label = LABEL_NOT_SPECIFIED;
585 cfg->rc_protocol = rtm->rtm_protocol;
586 cfg->rc_nlflags = nlh->nlmsg_flags;
587 cfg->rc_nlinfo.portid = NETLINK_CB(skb).portid;
588 cfg->rc_nlinfo.nlh = nlh;
589 cfg->rc_nlinfo.nl_net = sock_net(skb->sk);
591 for (index = 0; index <= RTA_MAX; index++) {
592 struct nlattr *nla = tb[index];
598 cfg->rc_ifindex = nla_get_u32(nla);
601 if (nla_get_labels(nla, MAX_NEW_LABELS,
602 &cfg->rc_output_labels,
603 cfg->rc_output_label))
609 if (nla_get_labels(nla, 1, &label_count,
613 /* The first 16 labels are reserved, and may not be set */
614 if (cfg->rc_label < 16)
621 struct rtvia *via = nla_data(nla);
622 if (nla_len(nla) < offsetof(struct rtvia, rtvia_addr))
624 cfg->rc_via_alen = nla_len(nla) -
625 offsetof(struct rtvia, rtvia_addr);
626 if (cfg->rc_via_alen > MAX_VIA_ALEN)
629 /* Validate the address family */
630 switch(via->rtvia_family) {
632 cfg->rc_via_table = NEIGH_LINK_TABLE;
635 cfg->rc_via_table = NEIGH_ARP_TABLE;
636 if (cfg->rc_via_alen != 4)
640 cfg->rc_via_table = NEIGH_ND_TABLE;
641 if (cfg->rc_via_alen != 16)
645 /* Unsupported address family */
649 memcpy(cfg->rc_via, via->rtvia_addr, cfg->rc_via_alen);
653 /* Unsupported attribute */
663 static int mpls_rtm_delroute(struct sk_buff *skb, struct nlmsghdr *nlh)
665 struct mpls_route_config cfg;
668 err = rtm_to_route_config(skb, nlh, &cfg);
672 return mpls_route_del(&cfg);
676 static int mpls_rtm_newroute(struct sk_buff *skb, struct nlmsghdr *nlh)
678 struct mpls_route_config cfg;
681 err = rtm_to_route_config(skb, nlh, &cfg);
685 return mpls_route_add(&cfg);
688 static int mpls_dump_route(struct sk_buff *skb, u32 portid, u32 seq, int event,
689 u32 label, struct mpls_route *rt, int flags)
691 struct net_device *dev;
692 struct nlmsghdr *nlh;
695 nlh = nlmsg_put(skb, portid, seq, event, sizeof(*rtm), flags);
699 rtm = nlmsg_data(nlh);
700 rtm->rtm_family = AF_MPLS;
701 rtm->rtm_dst_len = 20;
702 rtm->rtm_src_len = 0;
704 rtm->rtm_table = RT_TABLE_MAIN;
705 rtm->rtm_protocol = rt->rt_protocol;
706 rtm->rtm_scope = RT_SCOPE_UNIVERSE;
707 rtm->rtm_type = RTN_UNICAST;
711 nla_put_labels(skb, RTA_NEWDST, rt->rt_labels, rt->rt_label))
712 goto nla_put_failure;
713 if (nla_put_via(skb, rt->rt_via_table, rt->rt_via, rt->rt_via_alen))
714 goto nla_put_failure;
715 dev = rtnl_dereference(rt->rt_dev);
716 if (dev && nla_put_u32(skb, RTA_OIF, dev->ifindex))
717 goto nla_put_failure;
718 if (nla_put_labels(skb, RTA_DST, 1, &label))
719 goto nla_put_failure;
725 nlmsg_cancel(skb, nlh);
729 static int mpls_dump_routes(struct sk_buff *skb, struct netlink_callback *cb)
731 struct net *net = sock_net(skb->sk);
732 struct mpls_route __rcu **platform_label;
733 size_t platform_labels;
742 platform_label = rtnl_dereference(net->mpls.platform_label);
743 platform_labels = net->mpls.platform_labels;
744 for (; index < platform_labels; index++) {
745 struct mpls_route *rt;
746 rt = rtnl_dereference(platform_label[index]);
750 if (mpls_dump_route(skb, NETLINK_CB(cb->skb).portid,
751 cb->nlh->nlmsg_seq, RTM_NEWROUTE,
752 index, rt, NLM_F_MULTI) < 0)
760 static inline size_t lfib_nlmsg_size(struct mpls_route *rt)
763 NLMSG_ALIGN(sizeof(struct rtmsg))
764 + nla_total_size(2 + rt->rt_via_alen) /* RTA_VIA */
765 + nla_total_size(4); /* RTA_DST */
766 if (rt->rt_labels) /* RTA_NEWDST */
767 payload += nla_total_size(rt->rt_labels * 4);
768 if (rt->rt_dev) /* RTA_OIF */
769 payload += nla_total_size(4);
773 static void rtmsg_lfib(int event, u32 label, struct mpls_route *rt,
774 struct nlmsghdr *nlh, struct net *net, u32 portid,
775 unsigned int nlm_flags)
778 u32 seq = nlh ? nlh->nlmsg_seq : 0;
781 skb = nlmsg_new(lfib_nlmsg_size(rt), GFP_KERNEL);
785 err = mpls_dump_route(skb, portid, seq, event, label, rt, nlm_flags);
787 /* -EMSGSIZE implies BUG in lfib_nlmsg_size */
788 WARN_ON(err == -EMSGSIZE);
792 rtnl_notify(skb, net, portid, RTNLGRP_MPLS_ROUTE, nlh, GFP_KERNEL);
797 rtnl_set_sk_err(net, RTNLGRP_MPLS_ROUTE, err);
800 static int resize_platform_label_table(struct net *net, size_t limit)
802 size_t size = sizeof(struct mpls_route *) * limit;
805 struct mpls_route __rcu **labels = NULL, **old;
806 struct mpls_route *rt0 = NULL, *rt2 = NULL;
810 labels = kzalloc(size, GFP_KERNEL | __GFP_NOWARN | __GFP_NORETRY);
812 labels = vzalloc(size);
818 /* In case the predefined labels need to be populated */
819 if (limit > LABEL_IPV4_EXPLICIT_NULL) {
820 struct net_device *lo = net->loopback_dev;
821 rt0 = mpls_rt_alloc(lo->addr_len);
824 RCU_INIT_POINTER(rt0->rt_dev, lo);
825 rt0->rt_protocol = RTPROT_KERNEL;
826 rt0->rt_via_table = NEIGH_LINK_TABLE;
827 memcpy(rt0->rt_via, lo->dev_addr, lo->addr_len);
829 if (limit > LABEL_IPV6_EXPLICIT_NULL) {
830 struct net_device *lo = net->loopback_dev;
831 rt2 = mpls_rt_alloc(lo->addr_len);
834 RCU_INIT_POINTER(rt2->rt_dev, lo);
835 rt2->rt_protocol = RTPROT_KERNEL;
836 rt2->rt_via_table = NEIGH_LINK_TABLE;
837 memcpy(rt2->rt_via, lo->dev_addr, lo->addr_len);
841 /* Remember the original table */
842 old = rtnl_dereference(net->mpls.platform_label);
843 old_limit = net->mpls.platform_labels;
845 /* Free any labels beyond the new table */
846 for (index = limit; index < old_limit; index++)
847 mpls_route_update(net, index, NULL, NULL, NULL);
849 /* Copy over the old labels */
851 if (old_limit < limit)
852 cp_size = old_limit * sizeof(struct mpls_route *);
854 memcpy(labels, old, cp_size);
856 /* If needed set the predefined labels */
857 if ((old_limit <= LABEL_IPV6_EXPLICIT_NULL) &&
858 (limit > LABEL_IPV6_EXPLICIT_NULL)) {
859 RCU_INIT_POINTER(labels[LABEL_IPV6_EXPLICIT_NULL], rt2);
863 if ((old_limit <= LABEL_IPV4_EXPLICIT_NULL) &&
864 (limit > LABEL_IPV4_EXPLICIT_NULL)) {
865 RCU_INIT_POINTER(labels[LABEL_IPV4_EXPLICIT_NULL], rt0);
869 /* Update the global pointers */
870 net->mpls.platform_labels = limit;
871 rcu_assign_pointer(net->mpls.platform_label, labels);
892 static int mpls_platform_labels(struct ctl_table *table, int write,
893 void __user *buffer, size_t *lenp, loff_t *ppos)
895 struct net *net = table->data;
896 int platform_labels = net->mpls.platform_labels;
898 struct ctl_table tmp = {
899 .procname = table->procname,
900 .data = &platform_labels,
901 .maxlen = sizeof(int),
904 .extra2 = &label_limit,
907 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
909 if (write && ret == 0)
910 ret = resize_platform_label_table(net, platform_labels);
915 static struct ctl_table mpls_table[] = {
917 .procname = "platform_labels",
919 .maxlen = sizeof(int),
921 .proc_handler = mpls_platform_labels,
926 static int mpls_net_init(struct net *net)
928 struct ctl_table *table;
930 net->mpls.platform_labels = 0;
931 net->mpls.platform_label = NULL;
933 table = kmemdup(mpls_table, sizeof(mpls_table), GFP_KERNEL);
938 net->mpls.ctl = register_net_sysctl(net, "net/mpls", table);
939 if (net->mpls.ctl == NULL)
945 static void mpls_net_exit(struct net *net)
947 struct mpls_route __rcu **platform_label;
948 size_t platform_labels;
949 struct ctl_table *table;
952 table = net->mpls.ctl->ctl_table_arg;
953 unregister_net_sysctl_table(net->mpls.ctl);
956 /* An rcu grace period has passed since there was a device in
957 * the network namespace (and thus the last in flight packet)
958 * left this network namespace. This is because
959 * unregister_netdevice_many and netdev_run_todo has completed
960 * for each network device that was in this network namespace.
962 * As such no additional rcu synchronization is necessary when
963 * freeing the platform_label table.
966 platform_label = rtnl_dereference(net->mpls.platform_label);
967 platform_labels = net->mpls.platform_labels;
968 for (index = 0; index < platform_labels; index++) {
969 struct mpls_route *rt = rtnl_dereference(platform_label[index]);
970 RCU_INIT_POINTER(platform_label[index], NULL);
975 kvfree(platform_label);
978 static struct pernet_operations mpls_net_ops = {
979 .init = mpls_net_init,
980 .exit = mpls_net_exit,
983 static int __init mpls_init(void)
987 BUILD_BUG_ON(sizeof(struct mpls_shim_hdr) != 4);
989 err = register_pernet_subsys(&mpls_net_ops);
993 err = register_netdevice_notifier(&mpls_dev_notifier);
995 goto out_unregister_pernet;
997 dev_add_pack(&mpls_packet_type);
999 rtnl_register(PF_MPLS, RTM_NEWROUTE, mpls_rtm_newroute, NULL, NULL);
1000 rtnl_register(PF_MPLS, RTM_DELROUTE, mpls_rtm_delroute, NULL, NULL);
1001 rtnl_register(PF_MPLS, RTM_GETROUTE, NULL, mpls_dump_routes, NULL);
1006 out_unregister_pernet:
1007 unregister_pernet_subsys(&mpls_net_ops);
1010 module_init(mpls_init);
1012 static void __exit mpls_exit(void)
1014 rtnl_unregister_all(PF_MPLS);
1015 dev_remove_pack(&mpls_packet_type);
1016 unregister_netdevice_notifier(&mpls_dev_notifier);
1017 unregister_pernet_subsys(&mpls_net_ops);
1019 module_exit(mpls_exit);
1021 MODULE_DESCRIPTION("MultiProtocol Label Switching");
1022 MODULE_LICENSE("GPL v2");
1023 MODULE_ALIAS_NETPROTO(PF_MPLS);