1 /* Copyright (c) 2014 Mahesh Bandewar <maheshb@google.com>
3 * This program is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU General Public License as
5 * published by the Free Software Foundation; either version 2 of
6 * the License, or (at your option) any later version.
12 void ipvlan_adjust_mtu(struct ipvl_dev *ipvlan, struct net_device *dev)
14 ipvlan->dev->mtu = dev->mtu - ipvlan->mtu_adj;
17 void ipvlan_set_port_mode(struct ipvl_port *port, u32 nval)
19 struct ipvl_dev *ipvlan;
21 if (port->mode != nval) {
22 list_for_each_entry(ipvlan, &port->ipvlans, pnode) {
23 if (nval == IPVLAN_MODE_L3)
24 ipvlan->dev->flags |= IFF_NOARP;
26 ipvlan->dev->flags &= ~IFF_NOARP;
32 static int ipvlan_port_create(struct net_device *dev)
34 struct ipvl_port *port;
37 if (dev->type != ARPHRD_ETHER || dev->flags & IFF_LOOPBACK) {
38 netdev_err(dev, "Master is either lo or non-ether device\n");
41 port = kzalloc(sizeof(struct ipvl_port), GFP_KERNEL);
46 port->mode = IPVLAN_MODE_L3;
47 INIT_LIST_HEAD(&port->ipvlans);
48 for (idx = 0; idx < IPVLAN_HASH_SIZE; idx++)
49 INIT_HLIST_HEAD(&port->hlhead[idx]);
51 err = netdev_rx_handler_register(dev, ipvlan_handle_frame, port);
55 dev->priv_flags |= IFF_IPVLAN_MASTER;
63 static void ipvlan_port_destroy(struct net_device *dev)
65 struct ipvl_port *port = ipvlan_port_get_rtnl(dev);
67 dev->priv_flags &= ~IFF_IPVLAN_MASTER;
68 netdev_rx_handler_unregister(dev);
72 /* ipvlan network devices have devices nesting below it and are a special
73 * "super class" of normal network devices; split their locks off into a
74 * separate class since they always nest.
76 static struct lock_class_key ipvlan_netdev_xmit_lock_key;
77 static struct lock_class_key ipvlan_netdev_addr_lock_key;
79 #define IPVLAN_FEATURES \
80 (NETIF_F_SG | NETIF_F_ALL_CSUM | NETIF_F_HIGHDMA | NETIF_F_FRAGLIST | \
81 NETIF_F_GSO | NETIF_F_TSO | NETIF_F_UFO | NETIF_F_GSO_ROBUST | \
82 NETIF_F_TSO_ECN | NETIF_F_TSO6 | NETIF_F_GRO | NETIF_F_RXCSUM | \
83 NETIF_F_HW_VLAN_CTAG_FILTER | NETIF_F_HW_VLAN_STAG_FILTER)
85 #define IPVLAN_STATE_MASK \
86 ((1<<__LINK_STATE_NOCARRIER) | (1<<__LINK_STATE_DORMANT))
88 static void ipvlan_set_lockdep_class_one(struct net_device *dev,
89 struct netdev_queue *txq,
92 lockdep_set_class(&txq->_xmit_lock, &ipvlan_netdev_xmit_lock_key);
95 static void ipvlan_set_lockdep_class(struct net_device *dev)
97 lockdep_set_class(&dev->addr_list_lock, &ipvlan_netdev_addr_lock_key);
98 netdev_for_each_tx_queue(dev, ipvlan_set_lockdep_class_one, NULL);
101 static int ipvlan_init(struct net_device *dev)
103 struct ipvl_dev *ipvlan = netdev_priv(dev);
104 const struct net_device *phy_dev = ipvlan->phy_dev;
106 dev->state = (dev->state & ~IPVLAN_STATE_MASK) |
107 (phy_dev->state & IPVLAN_STATE_MASK);
108 dev->features = phy_dev->features & IPVLAN_FEATURES;
109 dev->features |= NETIF_F_LLTX;
110 dev->gso_max_size = phy_dev->gso_max_size;
111 dev->iflink = phy_dev->ifindex;
112 dev->hard_header_len = phy_dev->hard_header_len;
114 ipvlan_set_lockdep_class(dev);
116 ipvlan->pcpu_stats = alloc_percpu(struct ipvl_pcpu_stats);
117 if (!ipvlan->pcpu_stats)
123 static void ipvlan_uninit(struct net_device *dev)
125 struct ipvl_dev *ipvlan = netdev_priv(dev);
126 struct ipvl_port *port = ipvlan->port;
128 if (ipvlan->pcpu_stats)
129 free_percpu(ipvlan->pcpu_stats);
133 ipvlan_port_destroy(port->dev);
136 static int ipvlan_open(struct net_device *dev)
138 struct ipvl_dev *ipvlan = netdev_priv(dev);
139 struct net_device *phy_dev = ipvlan->phy_dev;
140 struct ipvl_addr *addr;
142 if (ipvlan->port->mode == IPVLAN_MODE_L3)
143 dev->flags |= IFF_NOARP;
145 dev->flags &= ~IFF_NOARP;
147 if (ipvlan->ipv6cnt > 0 || ipvlan->ipv4cnt > 0) {
148 list_for_each_entry(addr, &ipvlan->addrs, anode)
149 ipvlan_ht_addr_add(ipvlan, addr);
151 return dev_uc_add(phy_dev, phy_dev->dev_addr);
154 static int ipvlan_stop(struct net_device *dev)
156 struct ipvl_dev *ipvlan = netdev_priv(dev);
157 struct net_device *phy_dev = ipvlan->phy_dev;
158 struct ipvl_addr *addr;
160 dev_uc_unsync(phy_dev, dev);
161 dev_mc_unsync(phy_dev, dev);
163 dev_uc_del(phy_dev, phy_dev->dev_addr);
165 if (ipvlan->ipv6cnt > 0 || ipvlan->ipv4cnt > 0) {
166 list_for_each_entry(addr, &ipvlan->addrs, anode)
167 ipvlan_ht_addr_del(addr, !dev->dismantle);
172 static netdev_tx_t ipvlan_start_xmit(struct sk_buff *skb,
173 struct net_device *dev)
175 const struct ipvl_dev *ipvlan = netdev_priv(dev);
176 int skblen = skb->len;
179 ret = ipvlan_queue_xmit(skb, dev);
180 if (likely(ret == NET_XMIT_SUCCESS || ret == NET_XMIT_CN)) {
181 struct ipvl_pcpu_stats *pcptr;
183 pcptr = this_cpu_ptr(ipvlan->pcpu_stats);
185 u64_stats_update_begin(&pcptr->syncp);
187 pcptr->tx_bytes += skblen;
188 u64_stats_update_end(&pcptr->syncp);
190 this_cpu_inc(ipvlan->pcpu_stats->tx_drps);
195 static netdev_features_t ipvlan_fix_features(struct net_device *dev,
196 netdev_features_t features)
198 struct ipvl_dev *ipvlan = netdev_priv(dev);
200 return features & (ipvlan->sfeatures | ~IPVLAN_FEATURES);
203 static void ipvlan_change_rx_flags(struct net_device *dev, int change)
205 struct ipvl_dev *ipvlan = netdev_priv(dev);
206 struct net_device *phy_dev = ipvlan->phy_dev;
208 if (change & IFF_ALLMULTI)
209 dev_set_allmulti(phy_dev, dev->flags & IFF_ALLMULTI? 1 : -1);
212 static void ipvlan_set_broadcast_mac_filter(struct ipvl_dev *ipvlan, bool set)
214 struct net_device *dev = ipvlan->dev;
215 unsigned int hashbit = ipvlan_mac_hash(dev->broadcast);
217 if (set && !test_bit(hashbit, ipvlan->mac_filters))
218 __set_bit(hashbit, ipvlan->mac_filters);
219 else if (!set && test_bit(hashbit, ipvlan->mac_filters))
220 __clear_bit(hashbit, ipvlan->mac_filters);
223 static void ipvlan_set_multicast_mac_filter(struct net_device *dev)
225 struct ipvl_dev *ipvlan = netdev_priv(dev);
227 if (dev->flags & (IFF_PROMISC | IFF_ALLMULTI)) {
228 bitmap_fill(ipvlan->mac_filters, IPVLAN_MAC_FILTER_SIZE);
230 struct netdev_hw_addr *ha;
231 DECLARE_BITMAP(mc_filters, IPVLAN_MAC_FILTER_SIZE);
233 bitmap_zero(mc_filters, IPVLAN_MAC_FILTER_SIZE);
234 netdev_for_each_mc_addr(ha, dev)
235 __set_bit(ipvlan_mac_hash(ha->addr), mc_filters);
237 bitmap_copy(ipvlan->mac_filters, mc_filters,
238 IPVLAN_MAC_FILTER_SIZE);
240 dev_uc_sync(ipvlan->phy_dev, dev);
241 dev_mc_sync(ipvlan->phy_dev, dev);
244 static struct rtnl_link_stats64 *ipvlan_get_stats64(struct net_device *dev,
245 struct rtnl_link_stats64 *s)
247 struct ipvl_dev *ipvlan = netdev_priv(dev);
249 if (ipvlan->pcpu_stats) {
250 struct ipvl_pcpu_stats *pcptr;
251 u64 rx_pkts, rx_bytes, rx_mcast, tx_pkts, tx_bytes;
252 u32 rx_errs = 0, tx_drps = 0;
256 for_each_possible_cpu(idx) {
257 pcptr = per_cpu_ptr(ipvlan->pcpu_stats, idx);
259 strt= u64_stats_fetch_begin_irq(&pcptr->syncp);
260 rx_pkts = pcptr->rx_pkts;
261 rx_bytes = pcptr->rx_bytes;
262 rx_mcast = pcptr->rx_mcast;
263 tx_pkts = pcptr->tx_pkts;
264 tx_bytes = pcptr->tx_bytes;
265 } while (u64_stats_fetch_retry_irq(&pcptr->syncp,
268 s->rx_packets += rx_pkts;
269 s->rx_bytes += rx_bytes;
270 s->multicast += rx_mcast;
271 s->tx_packets += tx_pkts;
272 s->tx_bytes += tx_bytes;
274 /* u32 values are updated without syncp protection. */
275 rx_errs += pcptr->rx_errs;
276 tx_drps += pcptr->tx_drps;
278 s->rx_errors = rx_errs;
279 s->rx_dropped = rx_errs;
280 s->tx_dropped = tx_drps;
285 static int ipvlan_vlan_rx_add_vid(struct net_device *dev, __be16 proto, u16 vid)
287 struct ipvl_dev *ipvlan = netdev_priv(dev);
288 struct net_device *phy_dev = ipvlan->phy_dev;
290 return vlan_vid_add(phy_dev, proto, vid);
293 static int ipvlan_vlan_rx_kill_vid(struct net_device *dev, __be16 proto,
296 struct ipvl_dev *ipvlan = netdev_priv(dev);
297 struct net_device *phy_dev = ipvlan->phy_dev;
299 vlan_vid_del(phy_dev, proto, vid);
303 static const struct net_device_ops ipvlan_netdev_ops = {
304 .ndo_init = ipvlan_init,
305 .ndo_uninit = ipvlan_uninit,
306 .ndo_open = ipvlan_open,
307 .ndo_stop = ipvlan_stop,
308 .ndo_start_xmit = ipvlan_start_xmit,
309 .ndo_fix_features = ipvlan_fix_features,
310 .ndo_change_rx_flags = ipvlan_change_rx_flags,
311 .ndo_set_rx_mode = ipvlan_set_multicast_mac_filter,
312 .ndo_get_stats64 = ipvlan_get_stats64,
313 .ndo_vlan_rx_add_vid = ipvlan_vlan_rx_add_vid,
314 .ndo_vlan_rx_kill_vid = ipvlan_vlan_rx_kill_vid,
317 static int ipvlan_hard_header(struct sk_buff *skb, struct net_device *dev,
318 unsigned short type, const void *daddr,
319 const void *saddr, unsigned len)
321 const struct ipvl_dev *ipvlan = netdev_priv(dev);
322 struct net_device *phy_dev = ipvlan->phy_dev;
324 /* TODO Probably use a different field than dev_addr so that the
325 * mac-address on the virtual device is portable and can be carried
326 * while the packets use the mac-addr on the physical device.
328 return dev_hard_header(skb, phy_dev, type, daddr,
329 saddr ? : dev->dev_addr, len);
332 static const struct header_ops ipvlan_header_ops = {
333 .create = ipvlan_hard_header,
334 .rebuild = eth_rebuild_header,
335 .parse = eth_header_parse,
336 .cache = eth_header_cache,
337 .cache_update = eth_header_cache_update,
340 static int ipvlan_ethtool_get_settings(struct net_device *dev,
341 struct ethtool_cmd *cmd)
343 const struct ipvl_dev *ipvlan = netdev_priv(dev);
345 return __ethtool_get_settings(ipvlan->phy_dev, cmd);
348 static void ipvlan_ethtool_get_drvinfo(struct net_device *dev,
349 struct ethtool_drvinfo *drvinfo)
351 strlcpy(drvinfo->driver, IPVLAN_DRV, sizeof(drvinfo->driver));
352 strlcpy(drvinfo->version, IPV_DRV_VER, sizeof(drvinfo->version));
355 static u32 ipvlan_ethtool_get_msglevel(struct net_device *dev)
357 const struct ipvl_dev *ipvlan = netdev_priv(dev);
359 return ipvlan->msg_enable;
362 static void ipvlan_ethtool_set_msglevel(struct net_device *dev, u32 value)
364 struct ipvl_dev *ipvlan = netdev_priv(dev);
366 ipvlan->msg_enable = value;
369 static const struct ethtool_ops ipvlan_ethtool_ops = {
370 .get_link = ethtool_op_get_link,
371 .get_settings = ipvlan_ethtool_get_settings,
372 .get_drvinfo = ipvlan_ethtool_get_drvinfo,
373 .get_msglevel = ipvlan_ethtool_get_msglevel,
374 .set_msglevel = ipvlan_ethtool_set_msglevel,
377 static int ipvlan_nl_changelink(struct net_device *dev,
378 struct nlattr *tb[], struct nlattr *data[])
380 struct ipvl_dev *ipvlan = netdev_priv(dev);
381 struct ipvl_port *port = ipvlan_port_get_rtnl(ipvlan->phy_dev);
383 if (data && data[IFLA_IPVLAN_MODE]) {
384 u16 nmode = nla_get_u16(data[IFLA_IPVLAN_MODE]);
386 ipvlan_set_port_mode(port, nmode);
391 static size_t ipvlan_nl_getsize(const struct net_device *dev)
394 + nla_total_size(2) /* IFLA_IPVLAN_MODE */
398 static int ipvlan_nl_validate(struct nlattr *tb[], struct nlattr *data[])
400 if (data && data[IFLA_IPVLAN_MODE]) {
401 u16 mode = nla_get_u16(data[IFLA_IPVLAN_MODE]);
403 if (mode < IPVLAN_MODE_L2 || mode >= IPVLAN_MODE_MAX)
409 static int ipvlan_nl_fillinfo(struct sk_buff *skb,
410 const struct net_device *dev)
412 struct ipvl_dev *ipvlan = netdev_priv(dev);
413 struct ipvl_port *port = ipvlan_port_get_rtnl(ipvlan->phy_dev);
420 if (nla_put_u16(skb, IFLA_IPVLAN_MODE, port->mode))
429 static int ipvlan_link_new(struct net *src_net, struct net_device *dev,
430 struct nlattr *tb[], struct nlattr *data[])
432 struct ipvl_dev *ipvlan = netdev_priv(dev);
433 struct ipvl_port *port;
434 struct net_device *phy_dev;
440 phy_dev = __dev_get_by_index(src_net, nla_get_u32(tb[IFLA_LINK]));
444 if (ipvlan_dev_slave(phy_dev)) {
445 struct ipvl_dev *tmp = netdev_priv(phy_dev);
447 phy_dev = tmp->phy_dev;
448 } else if (!ipvlan_dev_master(phy_dev)) {
449 err = ipvlan_port_create(phy_dev);
454 port = ipvlan_port_get_rtnl(phy_dev);
455 if (data && data[IFLA_IPVLAN_MODE])
456 port->mode = nla_get_u16(data[IFLA_IPVLAN_MODE]);
458 ipvlan->phy_dev = phy_dev;
461 ipvlan->sfeatures = IPVLAN_FEATURES;
462 INIT_LIST_HEAD(&ipvlan->addrs);
466 /* TODO Probably put random address here to be presented to the
467 * world but keep using the physical-dev address for the outgoing
470 memcpy(dev->dev_addr, phy_dev->dev_addr, ETH_ALEN);
472 dev->priv_flags |= IFF_IPVLAN_SLAVE;
475 err = register_netdevice(dev);
477 goto ipvlan_destroy_port;
479 err = netdev_upper_dev_link(phy_dev, dev);
481 goto ipvlan_destroy_port;
483 list_add_tail_rcu(&ipvlan->pnode, &port->ipvlans);
484 netif_stacked_transfer_operstate(phy_dev, dev);
490 ipvlan_port_destroy(phy_dev);
495 static void ipvlan_link_delete(struct net_device *dev, struct list_head *head)
497 struct ipvl_dev *ipvlan = netdev_priv(dev);
498 struct ipvl_addr *addr, *next;
500 if (ipvlan->ipv6cnt > 0 || ipvlan->ipv4cnt > 0) {
501 list_for_each_entry_safe(addr, next, &ipvlan->addrs, anode) {
502 ipvlan_ht_addr_del(addr, !dev->dismantle);
503 list_del_rcu(&addr->anode);
506 list_del_rcu(&ipvlan->pnode);
507 unregister_netdevice_queue(dev, head);
508 netdev_upper_dev_unlink(ipvlan->phy_dev, dev);
511 static void ipvlan_link_setup(struct net_device *dev)
515 dev->priv_flags &= ~(IFF_XMIT_DST_RELEASE | IFF_TX_SKB_SHARING);
516 dev->priv_flags |= IFF_UNICAST_FLT;
517 dev->netdev_ops = &ipvlan_netdev_ops;
518 dev->destructor = free_netdev;
519 dev->header_ops = &ipvlan_header_ops;
520 dev->ethtool_ops = &ipvlan_ethtool_ops;
521 dev->tx_queue_len = 0;
524 static const struct nla_policy ipvlan_nl_policy[IFLA_IPVLAN_MAX + 1] =
526 [IFLA_IPVLAN_MODE] = { .type = NLA_U16 },
529 static struct rtnl_link_ops ipvlan_link_ops = {
531 .priv_size = sizeof(struct ipvl_dev),
533 .get_size = ipvlan_nl_getsize,
534 .policy = ipvlan_nl_policy,
535 .validate = ipvlan_nl_validate,
536 .fill_info = ipvlan_nl_fillinfo,
537 .changelink = ipvlan_nl_changelink,
538 .maxtype = IFLA_IPVLAN_MAX,
540 .setup = ipvlan_link_setup,
541 .newlink = ipvlan_link_new,
542 .dellink = ipvlan_link_delete,
545 static int ipvlan_link_register(struct rtnl_link_ops *ops)
547 return rtnl_link_register(ops);
550 static int ipvlan_device_event(struct notifier_block *unused,
551 unsigned long event, void *ptr)
553 struct net_device *dev = netdev_notifier_info_to_dev(ptr);
554 struct ipvl_dev *ipvlan, *next;
555 struct ipvl_port *port;
558 if (!ipvlan_dev_master(dev))
561 port = ipvlan_port_get_rtnl(dev);
565 list_for_each_entry(ipvlan, &port->ipvlans, pnode)
566 netif_stacked_transfer_operstate(ipvlan->phy_dev,
570 case NETDEV_UNREGISTER:
571 if (dev->reg_state != NETREG_UNREGISTERING)
574 list_for_each_entry_safe(ipvlan, next, &port->ipvlans,
576 ipvlan->dev->rtnl_link_ops->dellink(ipvlan->dev,
578 unregister_netdevice_many(&lst_kill);
581 case NETDEV_FEAT_CHANGE:
582 list_for_each_entry(ipvlan, &port->ipvlans, pnode) {
583 ipvlan->dev->features = dev->features & IPVLAN_FEATURES;
584 ipvlan->dev->gso_max_size = dev->gso_max_size;
585 netdev_features_change(ipvlan->dev);
589 case NETDEV_CHANGEMTU:
590 list_for_each_entry(ipvlan, &port->ipvlans, pnode)
591 ipvlan_adjust_mtu(ipvlan, dev);
594 case NETDEV_PRE_TYPE_CHANGE:
595 /* Forbid underlying device to change its type. */
601 static int ipvlan_add_addr6(struct ipvl_dev *ipvlan, struct in6_addr *ip6_addr)
603 struct ipvl_addr *addr;
605 if (ipvlan_addr_busy(ipvlan, ip6_addr, true)) {
606 netif_err(ipvlan, ifup, ipvlan->dev,
607 "Failed to add IPv6=%pI6c addr for %s intf\n",
608 ip6_addr, ipvlan->dev->name);
611 addr = kzalloc(sizeof(struct ipvl_addr), GFP_ATOMIC);
615 addr->master = ipvlan;
616 memcpy(&addr->ip6addr, ip6_addr, sizeof(struct in6_addr));
617 addr->atype = IPVL_IPV6;
618 list_add_tail_rcu(&addr->anode, &ipvlan->addrs);
620 ipvlan_ht_addr_add(ipvlan, addr);
625 static void ipvlan_del_addr6(struct ipvl_dev *ipvlan, struct in6_addr *ip6_addr)
627 struct ipvl_addr *addr;
629 addr = ipvlan_ht_addr_lookup(ipvlan->port, ip6_addr, true);
633 ipvlan_ht_addr_del(addr, true);
634 list_del_rcu(&addr->anode);
636 WARN_ON(ipvlan->ipv6cnt < 0);
637 kfree_rcu(addr, rcu);
642 static int ipvlan_addr6_event(struct notifier_block *unused,
643 unsigned long event, void *ptr)
645 struct inet6_ifaddr *if6 = (struct inet6_ifaddr *)ptr;
646 struct net_device *dev = (struct net_device *)if6->idev->dev;
647 struct ipvl_dev *ipvlan = netdev_priv(dev);
649 if (!ipvlan_dev_slave(dev))
652 if (!ipvlan || !ipvlan->port)
657 if (ipvlan_add_addr6(ipvlan, &if6->addr))
662 ipvlan_del_addr6(ipvlan, &if6->addr);
669 static int ipvlan_add_addr4(struct ipvl_dev *ipvlan, struct in_addr *ip4_addr)
671 struct ipvl_addr *addr;
673 if (ipvlan_addr_busy(ipvlan, ip4_addr, false)) {
674 netif_err(ipvlan, ifup, ipvlan->dev,
675 "Failed to add IPv4=%pI4 on %s intf.\n",
676 ip4_addr, ipvlan->dev->name);
679 addr = kzalloc(sizeof(struct ipvl_addr), GFP_KERNEL);
683 addr->master = ipvlan;
684 memcpy(&addr->ip4addr, ip4_addr, sizeof(struct in_addr));
685 addr->atype = IPVL_IPV4;
686 list_add_tail_rcu(&addr->anode, &ipvlan->addrs);
688 ipvlan_ht_addr_add(ipvlan, addr);
689 ipvlan_set_broadcast_mac_filter(ipvlan, true);
694 static void ipvlan_del_addr4(struct ipvl_dev *ipvlan, struct in_addr *ip4_addr)
696 struct ipvl_addr *addr;
698 addr = ipvlan_ht_addr_lookup(ipvlan->port, ip4_addr, false);
702 ipvlan_ht_addr_del(addr, true);
703 list_del_rcu(&addr->anode);
705 WARN_ON(ipvlan->ipv4cnt < 0);
706 if (!ipvlan->ipv4cnt)
707 ipvlan_set_broadcast_mac_filter(ipvlan, false);
708 kfree_rcu(addr, rcu);
713 static int ipvlan_addr4_event(struct notifier_block *unused,
714 unsigned long event, void *ptr)
716 struct in_ifaddr *if4 = (struct in_ifaddr *)ptr;
717 struct net_device *dev = (struct net_device *)if4->ifa_dev->dev;
718 struct ipvl_dev *ipvlan = netdev_priv(dev);
719 struct in_addr ip4_addr;
721 if (!ipvlan_dev_slave(dev))
724 if (!ipvlan || !ipvlan->port)
729 ip4_addr.s_addr = if4->ifa_address;
730 if (ipvlan_add_addr4(ipvlan, &ip4_addr))
735 ip4_addr.s_addr = if4->ifa_address;
736 ipvlan_del_addr4(ipvlan, &ip4_addr);
743 static struct notifier_block ipvlan_addr4_notifier_block __read_mostly = {
744 .notifier_call = ipvlan_addr4_event,
747 static struct notifier_block ipvlan_notifier_block __read_mostly = {
748 .notifier_call = ipvlan_device_event,
751 static struct notifier_block ipvlan_addr6_notifier_block __read_mostly = {
752 .notifier_call = ipvlan_addr6_event,
755 static int __init ipvlan_init_module(void)
759 ipvlan_init_secret();
760 register_netdevice_notifier(&ipvlan_notifier_block);
761 register_inet6addr_notifier(&ipvlan_addr6_notifier_block);
762 register_inetaddr_notifier(&ipvlan_addr4_notifier_block);
764 err = ipvlan_link_register(&ipvlan_link_ops);
770 unregister_inetaddr_notifier(&ipvlan_addr4_notifier_block);
771 unregister_inet6addr_notifier(&ipvlan_addr6_notifier_block);
772 unregister_netdevice_notifier(&ipvlan_notifier_block);
776 static void __exit ipvlan_cleanup_module(void)
778 rtnl_link_unregister(&ipvlan_link_ops);
779 unregister_netdevice_notifier(&ipvlan_notifier_block);
780 unregister_inetaddr_notifier(&ipvlan_addr4_notifier_block);
781 unregister_inet6addr_notifier(&ipvlan_addr6_notifier_block);
784 module_init(ipvlan_init_module);
785 module_exit(ipvlan_cleanup_module);
787 MODULE_LICENSE("GPL");
788 MODULE_AUTHOR("Mahesh Bandewar <maheshb@google.com>");
789 MODULE_DESCRIPTION("Driver for L3 (IPv6/IPv4) based VLANs");
790 MODULE_ALIAS_RTNL_LINK("ipvlan");