2 * vrf.c: device driver to encapsulate a VRF space
4 * Copyright (c) 2015 Cumulus Networks. All rights reserved.
5 * Copyright (c) 2015 Shrijeet Mukherjee <shm@cumulusnetworks.com>
6 * Copyright (c) 2015 David Ahern <dsa@cumulusnetworks.com>
8 * Based on dummy, team and ipvlan drivers
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
16 #include <linux/module.h>
17 #include <linux/kernel.h>
18 #include <linux/netdevice.h>
19 #include <linux/etherdevice.h>
21 #include <linux/init.h>
22 #include <linux/moduleparam.h>
23 #include <linux/netfilter.h>
24 #include <linux/rtnetlink.h>
25 #include <net/rtnetlink.h>
26 #include <linux/u64_stats_sync.h>
27 #include <linux/hashtable.h>
29 #include <linux/inetdevice.h>
32 #include <net/ip_fib.h>
33 #include <net/ip6_fib.h>
34 #include <net/ip6_route.h>
35 #include <net/route.h>
36 #include <net/addrconf.h>
37 #include <net/l3mdev.h>
39 #define RT_FL_TOS(oldflp4) \
40 ((oldflp4)->flowi4_tos & (IPTOS_RT_MASK | RTO_ONLINK))
42 #define DRV_NAME "vrf"
43 #define DRV_VERSION "1.0"
45 #define vrf_master_get_rcu(dev) \
46 ((struct net_device *)rcu_dereference(dev->rx_handler_data))
60 struct u64_stats_sync syncp
;
63 /* neighbor handling is done with actual device; do not want
64 * to flip skb->dev for those ndisc packets. This really fails
65 * for multiple next protocols (e.g., NEXTHDR_HOP). But it is
68 #if IS_ENABLED(CONFIG_IPV6)
69 static bool check_ipv6_frame(const struct sk_buff
*skb
)
71 const struct ipv6hdr
*ipv6h
;
72 struct ipv6hdr _ipv6h
;
75 ipv6h
= skb_header_pointer(skb
, 0, sizeof(_ipv6h
), &_ipv6h
);
79 if (ipv6h
->nexthdr
== NEXTHDR_ICMP
) {
80 const struct icmp6hdr
*icmph
;
81 struct icmp6hdr _icmph
;
83 icmph
= skb_header_pointer(skb
, sizeof(_ipv6h
),
84 sizeof(_icmph
), &_icmph
);
88 switch (icmph
->icmp6_type
) {
89 case NDISC_ROUTER_SOLICITATION
:
90 case NDISC_ROUTER_ADVERTISEMENT
:
91 case NDISC_NEIGHBOUR_SOLICITATION
:
92 case NDISC_NEIGHBOUR_ADVERTISEMENT
:
103 static bool check_ipv6_frame(const struct sk_buff
*skb
)
109 static bool is_ip_rx_frame(struct sk_buff
*skb
)
111 switch (skb
->protocol
) {
112 case htons(ETH_P_IP
):
114 case htons(ETH_P_IPV6
):
115 return check_ipv6_frame(skb
);
120 static void vrf_tx_error(struct net_device
*vrf_dev
, struct sk_buff
*skb
)
122 vrf_dev
->stats
.tx_errors
++;
126 /* note: already called with rcu_read_lock */
127 static rx_handler_result_t
vrf_handle_frame(struct sk_buff
**pskb
)
129 struct sk_buff
*skb
= *pskb
;
131 if (is_ip_rx_frame(skb
)) {
132 struct net_device
*dev
= vrf_master_get_rcu(skb
->dev
);
133 struct pcpu_dstats
*dstats
= this_cpu_ptr(dev
->dstats
);
135 u64_stats_update_begin(&dstats
->syncp
);
137 dstats
->rx_bytes
+= skb
->len
;
138 u64_stats_update_end(&dstats
->syncp
);
142 return RX_HANDLER_ANOTHER
;
144 return RX_HANDLER_PASS
;
147 static struct rtnl_link_stats64
*vrf_get_stats64(struct net_device
*dev
,
148 struct rtnl_link_stats64
*stats
)
152 for_each_possible_cpu(i
) {
153 const struct pcpu_dstats
*dstats
;
154 u64 tbytes
, tpkts
, tdrops
, rbytes
, rpkts
;
157 dstats
= per_cpu_ptr(dev
->dstats
, i
);
159 start
= u64_stats_fetch_begin_irq(&dstats
->syncp
);
160 tbytes
= dstats
->tx_bytes
;
161 tpkts
= dstats
->tx_pkts
;
162 tdrops
= dstats
->tx_drps
;
163 rbytes
= dstats
->rx_bytes
;
164 rpkts
= dstats
->rx_pkts
;
165 } while (u64_stats_fetch_retry_irq(&dstats
->syncp
, start
));
166 stats
->tx_bytes
+= tbytes
;
167 stats
->tx_packets
+= tpkts
;
168 stats
->tx_dropped
+= tdrops
;
169 stats
->rx_bytes
+= rbytes
;
170 stats
->rx_packets
+= rpkts
;
175 #if IS_ENABLED(CONFIG_IPV6)
176 static netdev_tx_t
vrf_process_v6_outbound(struct sk_buff
*skb
,
177 struct net_device
*dev
)
179 const struct ipv6hdr
*iph
= ipv6_hdr(skb
);
180 struct net
*net
= dev_net(skb
->dev
);
181 struct flowi6 fl6
= {
182 /* needed to match OIF rule */
183 .flowi6_oif
= dev
->ifindex
,
184 .flowi6_iif
= LOOPBACK_IFINDEX
,
187 .flowlabel
= ip6_flowinfo(iph
),
188 .flowi6_mark
= skb
->mark
,
189 .flowi6_proto
= iph
->nexthdr
,
190 .flowi6_flags
= FLOWI_FLAG_L3MDEV_SRC
| FLOWI_FLAG_SKIP_NH_OIF
,
192 int ret
= NET_XMIT_DROP
;
193 struct dst_entry
*dst
;
194 struct dst_entry
*dst_null
= &net
->ipv6
.ip6_null_entry
->dst
;
196 dst
= ip6_route_output(net
, NULL
, &fl6
);
201 skb_dst_set(skb
, dst
);
203 ret
= ip6_local_out(net
, skb
->sk
, skb
);
204 if (unlikely(net_xmit_eval(ret
)))
205 dev
->stats
.tx_errors
++;
207 ret
= NET_XMIT_SUCCESS
;
211 vrf_tx_error(dev
, skb
);
212 return NET_XMIT_DROP
;
215 static netdev_tx_t
vrf_process_v6_outbound(struct sk_buff
*skb
,
216 struct net_device
*dev
)
218 vrf_tx_error(dev
, skb
);
219 return NET_XMIT_DROP
;
223 static int vrf_send_v4_prep(struct sk_buff
*skb
, struct flowi4
*fl4
,
224 struct net_device
*vrf_dev
)
229 rt
= ip_route_output_flow(dev_net(vrf_dev
), fl4
, NULL
);
233 /* TO-DO: what about broadcast ? */
234 if (rt
->rt_type
!= RTN_UNICAST
&& rt
->rt_type
!= RTN_LOCAL
) {
240 skb_dst_set(skb
, &rt
->dst
);
246 static netdev_tx_t
vrf_process_v4_outbound(struct sk_buff
*skb
,
247 struct net_device
*vrf_dev
)
249 struct iphdr
*ip4h
= ip_hdr(skb
);
250 int ret
= NET_XMIT_DROP
;
251 struct flowi4 fl4
= {
252 /* needed to match OIF rule */
253 .flowi4_oif
= vrf_dev
->ifindex
,
254 .flowi4_iif
= LOOPBACK_IFINDEX
,
255 .flowi4_tos
= RT_TOS(ip4h
->tos
),
256 .flowi4_flags
= FLOWI_FLAG_ANYSRC
| FLOWI_FLAG_L3MDEV_SRC
|
257 FLOWI_FLAG_SKIP_NH_OIF
,
258 .daddr
= ip4h
->daddr
,
261 if (vrf_send_v4_prep(skb
, &fl4
, vrf_dev
))
265 ip4h
->saddr
= inet_select_addr(skb_dst(skb
)->dev
, 0,
269 ret
= ip_local_out(dev_net(skb_dst(skb
)->dev
), skb
->sk
, skb
);
270 if (unlikely(net_xmit_eval(ret
)))
271 vrf_dev
->stats
.tx_errors
++;
273 ret
= NET_XMIT_SUCCESS
;
278 vrf_tx_error(vrf_dev
, skb
);
282 static netdev_tx_t
is_ip_tx_frame(struct sk_buff
*skb
, struct net_device
*dev
)
284 /* strip the ethernet header added for pass through VRF device */
285 __skb_pull(skb
, skb_network_offset(skb
));
287 switch (skb
->protocol
) {
288 case htons(ETH_P_IP
):
289 return vrf_process_v4_outbound(skb
, dev
);
290 case htons(ETH_P_IPV6
):
291 return vrf_process_v6_outbound(skb
, dev
);
293 vrf_tx_error(dev
, skb
);
294 return NET_XMIT_DROP
;
298 static netdev_tx_t
vrf_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
300 netdev_tx_t ret
= is_ip_tx_frame(skb
, dev
);
302 if (likely(ret
== NET_XMIT_SUCCESS
|| ret
== NET_XMIT_CN
)) {
303 struct pcpu_dstats
*dstats
= this_cpu_ptr(dev
->dstats
);
305 u64_stats_update_begin(&dstats
->syncp
);
307 dstats
->tx_bytes
+= skb
->len
;
308 u64_stats_update_end(&dstats
->syncp
);
310 this_cpu_inc(dev
->dstats
->tx_drps
);
316 #if IS_ENABLED(CONFIG_IPV6)
317 /* modelled after ip6_finish_output2 */
318 static int vrf_finish_output6(struct net
*net
, struct sock
*sk
,
321 struct dst_entry
*dst
= skb_dst(skb
);
322 struct net_device
*dev
= dst
->dev
;
323 struct neighbour
*neigh
;
324 struct in6_addr
*nexthop
;
327 skb
->protocol
= htons(ETH_P_IPV6
);
331 nexthop
= rt6_nexthop((struct rt6_info
*)dst
, &ipv6_hdr(skb
)->daddr
);
332 neigh
= __ipv6_neigh_lookup_noref(dst
->dev
, nexthop
);
333 if (unlikely(!neigh
))
334 neigh
= __neigh_create(&nd_tbl
, nexthop
, dst
->dev
, false);
335 if (!IS_ERR(neigh
)) {
336 ret
= dst_neigh_output(dst
, neigh
, skb
);
337 rcu_read_unlock_bh();
340 rcu_read_unlock_bh();
342 IP6_INC_STATS(dev_net(dst
->dev
),
343 ip6_dst_idev(dst
), IPSTATS_MIB_OUTNOROUTES
);
348 /* modelled after ip6_output */
349 static int vrf_output6(struct net
*net
, struct sock
*sk
, struct sk_buff
*skb
)
351 return NF_HOOK_COND(NFPROTO_IPV6
, NF_INET_POST_ROUTING
,
352 net
, sk
, skb
, NULL
, skb_dst(skb
)->dev
,
354 !(IP6CB(skb
)->flags
& IP6SKB_REROUTED
));
357 static void vrf_rt6_release(struct net_vrf
*vrf
)
359 dst_release(&vrf
->rt6
->dst
);
363 static int vrf_rt6_create(struct net_device
*dev
)
365 struct net_vrf
*vrf
= netdev_priv(dev
);
366 struct net
*net
= dev_net(dev
);
367 struct rt6_info
*rt6
;
370 rt6
= ip6_dst_alloc(net
, dev
,
371 DST_HOST
| DST_NOPOLICY
| DST_NOXFRM
| DST_NOCACHE
);
375 rt6
->dst
.output
= vrf_output6
;
376 rt6
->rt6i_table
= fib6_get_table(net
, vrf
->tb_id
);
384 static void vrf_rt6_release(struct net_vrf
*vrf
)
388 static int vrf_rt6_create(struct net_device
*dev
)
394 /* modelled after ip_finish_output2 */
395 static int vrf_finish_output(struct net
*net
, struct sock
*sk
, struct sk_buff
*skb
)
397 struct dst_entry
*dst
= skb_dst(skb
);
398 struct rtable
*rt
= (struct rtable
*)dst
;
399 struct net_device
*dev
= dst
->dev
;
400 unsigned int hh_len
= LL_RESERVED_SPACE(dev
);
401 struct neighbour
*neigh
;
405 /* Be paranoid, rather than too clever. */
406 if (unlikely(skb_headroom(skb
) < hh_len
&& dev
->header_ops
)) {
407 struct sk_buff
*skb2
;
409 skb2
= skb_realloc_headroom(skb
, LL_RESERVED_SPACE(dev
));
415 skb_set_owner_w(skb2
, skb
->sk
);
423 nexthop
= (__force u32
)rt_nexthop(rt
, ip_hdr(skb
)->daddr
);
424 neigh
= __ipv4_neigh_lookup_noref(dev
, nexthop
);
425 if (unlikely(!neigh
))
426 neigh
= __neigh_create(&arp_tbl
, &nexthop
, dev
, false);
428 ret
= dst_neigh_output(dst
, neigh
, skb
);
430 rcu_read_unlock_bh();
432 if (unlikely(ret
< 0))
433 vrf_tx_error(skb
->dev
, skb
);
437 static int vrf_output(struct net
*net
, struct sock
*sk
, struct sk_buff
*skb
)
439 struct net_device
*dev
= skb_dst(skb
)->dev
;
441 IP_UPD_PO_STATS(net
, IPSTATS_MIB_OUT
, skb
->len
);
444 skb
->protocol
= htons(ETH_P_IP
);
446 return NF_HOOK_COND(NFPROTO_IPV4
, NF_INET_POST_ROUTING
,
447 net
, sk
, skb
, NULL
, dev
,
449 !(IPCB(skb
)->flags
& IPSKB_REROUTED
));
452 static void vrf_rtable_release(struct net_vrf
*vrf
)
454 struct dst_entry
*dst
= (struct dst_entry
*)vrf
->rth
;
460 static struct rtable
*vrf_rtable_create(struct net_device
*dev
)
462 struct net_vrf
*vrf
= netdev_priv(dev
);
465 rth
= rt_dst_alloc(dev
, 0, RTN_UNICAST
, 1, 1, 0);
467 rth
->dst
.output
= vrf_output
;
468 rth
->rt_table_id
= vrf
->tb_id
;
474 /**************************** device handling ********************/
476 /* cycle interface to flush neighbor cache and move routes across tables */
477 static void cycle_netdev(struct net_device
*dev
)
479 unsigned int flags
= dev
->flags
;
482 if (!netif_running(dev
))
485 ret
= dev_change_flags(dev
, flags
& ~IFF_UP
);
487 ret
= dev_change_flags(dev
, flags
);
491 "Failed to cycle device %s; route tables might be wrong!\n",
496 static int do_vrf_add_slave(struct net_device
*dev
, struct net_device
*port_dev
)
500 /* register the packet handler for slave ports */
501 ret
= netdev_rx_handler_register(port_dev
, vrf_handle_frame
, dev
);
504 "Device %s failed to register rx_handler\n",
509 ret
= netdev_master_upper_dev_link(port_dev
, dev
, NULL
, NULL
);
513 port_dev
->priv_flags
|= IFF_L3MDEV_SLAVE
;
514 cycle_netdev(port_dev
);
519 netdev_rx_handler_unregister(port_dev
);
524 static int vrf_add_slave(struct net_device
*dev
, struct net_device
*port_dev
)
526 if (netif_is_l3_master(port_dev
) || netif_is_l3_slave(port_dev
))
529 return do_vrf_add_slave(dev
, port_dev
);
532 /* inverse of do_vrf_add_slave */
533 static int do_vrf_del_slave(struct net_device
*dev
, struct net_device
*port_dev
)
535 netdev_upper_dev_unlink(port_dev
, dev
);
536 port_dev
->priv_flags
&= ~IFF_L3MDEV_SLAVE
;
538 netdev_rx_handler_unregister(port_dev
);
540 cycle_netdev(port_dev
);
545 static int vrf_del_slave(struct net_device
*dev
, struct net_device
*port_dev
)
547 return do_vrf_del_slave(dev
, port_dev
);
550 static void vrf_dev_uninit(struct net_device
*dev
)
552 struct net_vrf
*vrf
= netdev_priv(dev
);
553 struct net_device
*port_dev
;
554 struct list_head
*iter
;
556 vrf_rtable_release(vrf
);
557 vrf_rt6_release(vrf
);
559 netdev_for_each_lower_dev(dev
, port_dev
, iter
)
560 vrf_del_slave(dev
, port_dev
);
562 free_percpu(dev
->dstats
);
566 static int vrf_dev_init(struct net_device
*dev
)
568 struct net_vrf
*vrf
= netdev_priv(dev
);
570 dev
->dstats
= netdev_alloc_pcpu_stats(struct pcpu_dstats
);
574 /* create the default dst which points back to us */
575 vrf
->rth
= vrf_rtable_create(dev
);
579 if (vrf_rt6_create(dev
) != 0)
582 dev
->flags
= IFF_MASTER
| IFF_NOARP
;
587 vrf_rtable_release(vrf
);
589 free_percpu(dev
->dstats
);
595 static const struct net_device_ops vrf_netdev_ops
= {
596 .ndo_init
= vrf_dev_init
,
597 .ndo_uninit
= vrf_dev_uninit
,
598 .ndo_start_xmit
= vrf_xmit
,
599 .ndo_get_stats64
= vrf_get_stats64
,
600 .ndo_add_slave
= vrf_add_slave
,
601 .ndo_del_slave
= vrf_del_slave
,
604 static u32
vrf_fib_table(const struct net_device
*dev
)
606 struct net_vrf
*vrf
= netdev_priv(dev
);
611 static struct rtable
*vrf_get_rtable(const struct net_device
*dev
,
612 const struct flowi4
*fl4
)
614 struct rtable
*rth
= NULL
;
616 if (!(fl4
->flowi4_flags
& FLOWI_FLAG_L3MDEV_SRC
)) {
617 struct net_vrf
*vrf
= netdev_priv(dev
);
626 /* called under rcu_read_lock */
627 static int vrf_get_saddr(struct net_device
*dev
, struct flowi4
*fl4
)
629 struct fib_result res
= { .tclassid
= 0 };
630 struct net
*net
= dev_net(dev
);
631 u32 orig_tos
= fl4
->flowi4_tos
;
632 u8 flags
= fl4
->flowi4_flags
;
633 u8 scope
= fl4
->flowi4_scope
;
634 u8 tos
= RT_FL_TOS(fl4
);
637 if (unlikely(!fl4
->daddr
))
640 fl4
->flowi4_flags
|= FLOWI_FLAG_SKIP_NH_OIF
;
641 fl4
->flowi4_iif
= LOOPBACK_IFINDEX
;
642 fl4
->flowi4_tos
= tos
& IPTOS_RT_MASK
;
643 fl4
->flowi4_scope
= ((tos
& RTO_ONLINK
) ?
644 RT_SCOPE_LINK
: RT_SCOPE_UNIVERSE
);
646 rc
= fib_lookup(net
, fl4
, &res
, 0);
648 if (res
.type
== RTN_LOCAL
)
649 fl4
->saddr
= res
.fi
->fib_prefsrc
? : fl4
->daddr
;
651 fib_select_path(net
, &res
, fl4
, -1);
654 fl4
->flowi4_flags
= flags
;
655 fl4
->flowi4_tos
= orig_tos
;
656 fl4
->flowi4_scope
= scope
;
661 #if IS_ENABLED(CONFIG_IPV6)
662 static struct dst_entry
*vrf_get_rt6_dst(const struct net_device
*dev
,
663 const struct flowi6
*fl6
)
665 struct rt6_info
*rt
= NULL
;
667 if (!(fl6
->flowi6_flags
& FLOWI_FLAG_L3MDEV_SRC
)) {
668 struct net_vrf
*vrf
= netdev_priv(dev
);
674 return (struct dst_entry
*)rt
;
678 static const struct l3mdev_ops vrf_l3mdev_ops
= {
679 .l3mdev_fib_table
= vrf_fib_table
,
680 .l3mdev_get_rtable
= vrf_get_rtable
,
681 .l3mdev_get_saddr
= vrf_get_saddr
,
682 #if IS_ENABLED(CONFIG_IPV6)
683 .l3mdev_get_rt6_dst
= vrf_get_rt6_dst
,
687 static void vrf_get_drvinfo(struct net_device
*dev
,
688 struct ethtool_drvinfo
*info
)
690 strlcpy(info
->driver
, DRV_NAME
, sizeof(info
->driver
));
691 strlcpy(info
->version
, DRV_VERSION
, sizeof(info
->version
));
694 static const struct ethtool_ops vrf_ethtool_ops
= {
695 .get_drvinfo
= vrf_get_drvinfo
,
698 static void vrf_setup(struct net_device
*dev
)
702 /* Initialize the device structure. */
703 dev
->netdev_ops
= &vrf_netdev_ops
;
704 dev
->l3mdev_ops
= &vrf_l3mdev_ops
;
705 dev
->ethtool_ops
= &vrf_ethtool_ops
;
706 dev
->destructor
= free_netdev
;
708 /* Fill in device structure with ethernet-generic values. */
709 eth_hw_addr_random(dev
);
711 /* don't acquire vrf device's netif_tx_lock when transmitting */
712 dev
->features
|= NETIF_F_LLTX
;
714 /* don't allow vrf devices to change network namespaces. */
715 dev
->features
|= NETIF_F_NETNS_LOCAL
;
718 static int vrf_validate(struct nlattr
*tb
[], struct nlattr
*data
[])
720 if (tb
[IFLA_ADDRESS
]) {
721 if (nla_len(tb
[IFLA_ADDRESS
]) != ETH_ALEN
)
723 if (!is_valid_ether_addr(nla_data(tb
[IFLA_ADDRESS
])))
724 return -EADDRNOTAVAIL
;
729 static void vrf_dellink(struct net_device
*dev
, struct list_head
*head
)
731 unregister_netdevice_queue(dev
, head
);
734 static int vrf_newlink(struct net
*src_net
, struct net_device
*dev
,
735 struct nlattr
*tb
[], struct nlattr
*data
[])
737 struct net_vrf
*vrf
= netdev_priv(dev
);
739 if (!data
|| !data
[IFLA_VRF_TABLE
])
742 vrf
->tb_id
= nla_get_u32(data
[IFLA_VRF_TABLE
]);
744 dev
->priv_flags
|= IFF_L3MDEV_MASTER
;
746 return register_netdevice(dev
);
749 static size_t vrf_nl_getsize(const struct net_device
*dev
)
751 return nla_total_size(sizeof(u32
)); /* IFLA_VRF_TABLE */
754 static int vrf_fillinfo(struct sk_buff
*skb
,
755 const struct net_device
*dev
)
757 struct net_vrf
*vrf
= netdev_priv(dev
);
759 return nla_put_u32(skb
, IFLA_VRF_TABLE
, vrf
->tb_id
);
762 static size_t vrf_get_slave_size(const struct net_device
*bond_dev
,
763 const struct net_device
*slave_dev
)
765 return nla_total_size(sizeof(u32
)); /* IFLA_VRF_PORT_TABLE */
768 static int vrf_fill_slave_info(struct sk_buff
*skb
,
769 const struct net_device
*vrf_dev
,
770 const struct net_device
*slave_dev
)
772 struct net_vrf
*vrf
= netdev_priv(vrf_dev
);
774 if (nla_put_u32(skb
, IFLA_VRF_PORT_TABLE
, vrf
->tb_id
))
780 static const struct nla_policy vrf_nl_policy
[IFLA_VRF_MAX
+ 1] = {
781 [IFLA_VRF_TABLE
] = { .type
= NLA_U32
},
784 static struct rtnl_link_ops vrf_link_ops __read_mostly
= {
786 .priv_size
= sizeof(struct net_vrf
),
788 .get_size
= vrf_nl_getsize
,
789 .policy
= vrf_nl_policy
,
790 .validate
= vrf_validate
,
791 .fill_info
= vrf_fillinfo
,
793 .get_slave_size
= vrf_get_slave_size
,
794 .fill_slave_info
= vrf_fill_slave_info
,
796 .newlink
= vrf_newlink
,
797 .dellink
= vrf_dellink
,
799 .maxtype
= IFLA_VRF_MAX
,
802 static int vrf_device_event(struct notifier_block
*unused
,
803 unsigned long event
, void *ptr
)
805 struct net_device
*dev
= netdev_notifier_info_to_dev(ptr
);
807 /* only care about unregister events to drop slave references */
808 if (event
== NETDEV_UNREGISTER
) {
809 struct net_device
*vrf_dev
;
811 if (!netif_is_l3_slave(dev
))
814 vrf_dev
= netdev_master_upper_dev_get(dev
);
815 vrf_del_slave(vrf_dev
, dev
);
821 static struct notifier_block vrf_notifier_block __read_mostly
= {
822 .notifier_call
= vrf_device_event
,
825 static int __init
vrf_init_module(void)
829 register_netdevice_notifier(&vrf_notifier_block
);
831 rc
= rtnl_link_register(&vrf_link_ops
);
838 unregister_netdevice_notifier(&vrf_notifier_block
);
842 module_init(vrf_init_module
);
843 MODULE_AUTHOR("Shrijeet Mukherjee, David Ahern");
844 MODULE_DESCRIPTION("Device driver to instantiate VRF domains");
845 MODULE_LICENSE("GPL");
846 MODULE_ALIAS_RTNL_LINK(DRV_NAME
);
847 MODULE_VERSION(DRV_VERSION
);