]> git.ipfire.org Git - thirdparty/kernel/stable.git/blame - drivers/net/ipvlan/ipvlan_main.c
ipvlan: Remove a useless comparison
[thirdparty/kernel/stable.git] / drivers / net / ipvlan / ipvlan_main.c
CommitLineData
2ad7bf36
MB
1/* Copyright (c) 2014 Mahesh Bandewar <maheshb@google.com>
2 *
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.
7 *
8 */
9
10#include "ipvlan.h"
11
3133822f
FW
12static unsigned int ipvlan_netid __read_mostly;
13
14struct ipvlan_netns {
15 unsigned int ipvl_nf_hook_refcnt;
16};
4fbae7d8 17
591bb278 18static const struct nf_hook_ops ipvl_nfops[] = {
4fbae7d8
MB
19 {
20 .hook = ipvlan_nf_input,
21 .pf = NFPROTO_IPV4,
22 .hooknum = NF_INET_LOCAL_IN,
23 .priority = INT_MAX,
24 },
94333fac 25#if IS_ENABLED(CONFIG_IPV6)
4fbae7d8
MB
26 {
27 .hook = ipvlan_nf_input,
28 .pf = NFPROTO_IPV6,
29 .hooknum = NF_INET_LOCAL_IN,
30 .priority = INT_MAX,
31 },
94333fac 32#endif
4fbae7d8
MB
33};
34
ab530f63 35static const struct l3mdev_ops ipvl_l3mdev_ops = {
4fbae7d8
MB
36 .l3mdev_l3_rcv = ipvlan_l3_rcv,
37};
38
ab5b7013 39static void ipvlan_adjust_mtu(struct ipvl_dev *ipvlan, struct net_device *dev)
2ad7bf36 40{
8f679ed8 41 ipvlan->dev->mtu = dev->mtu;
2ad7bf36
MB
42}
43
3133822f 44static int ipvlan_register_nf_hook(struct net *net)
4fbae7d8 45{
3133822f 46 struct ipvlan_netns *vnet = net_generic(net, ipvlan_netid);
4fbae7d8
MB
47 int err = 0;
48
3133822f
FW
49 if (!vnet->ipvl_nf_hook_refcnt) {
50 err = nf_register_net_hooks(net, ipvl_nfops,
51 ARRAY_SIZE(ipvl_nfops));
4fbae7d8 52 if (!err)
3133822f 53 vnet->ipvl_nf_hook_refcnt = 1;
4fbae7d8 54 } else {
3133822f 55 vnet->ipvl_nf_hook_refcnt++;
4fbae7d8
MB
56 }
57
58 return err;
59}
60
3133822f 61static void ipvlan_unregister_nf_hook(struct net *net)
4fbae7d8 62{
3133822f
FW
63 struct ipvlan_netns *vnet = net_generic(net, ipvlan_netid);
64
65 if (WARN_ON(!vnet->ipvl_nf_hook_refcnt))
66 return;
4fbae7d8 67
3133822f
FW
68 vnet->ipvl_nf_hook_refcnt--;
69 if (!vnet->ipvl_nf_hook_refcnt)
70 nf_unregister_net_hooks(net, ipvl_nfops,
71 ARRAY_SIZE(ipvl_nfops));
4fbae7d8
MB
72}
73
cf7686a0
PM
74static int ipvlan_set_port_mode(struct ipvl_port *port, u16 nval,
75 struct netlink_ext_ack *extack)
2ad7bf36
MB
76{
77 struct ipvl_dev *ipvlan;
4fbae7d8 78 struct net_device *mdev = port->dev;
5dc2d399
HL
79 unsigned int flags;
80 int err;
2ad7bf36 81
4fbae7d8 82 ASSERT_RTNL();
2ad7bf36 83 if (port->mode != nval) {
5dc2d399
HL
84 list_for_each_entry(ipvlan, &port->ipvlans, pnode) {
85 flags = ipvlan->dev->flags;
86 if (nval == IPVLAN_MODE_L3 || nval == IPVLAN_MODE_L3S) {
87 err = dev_change_flags(ipvlan->dev,
567c5e13
PM
88 flags | IFF_NOARP,
89 extack);
5dc2d399
HL
90 } else {
91 err = dev_change_flags(ipvlan->dev,
567c5e13
PM
92 flags & ~IFF_NOARP,
93 extack);
5dc2d399
HL
94 }
95 if (unlikely(err))
96 goto fail;
97 }
4fbae7d8
MB
98 if (nval == IPVLAN_MODE_L3S) {
99 /* New mode is L3S */
3133822f 100 err = ipvlan_register_nf_hook(read_pnet(&port->pnet));
4fbae7d8
MB
101 if (!err) {
102 mdev->l3mdev_ops = &ipvl_l3mdev_ops;
103 mdev->priv_flags |= IFF_L3MDEV_MASTER;
104 } else
5dc2d399 105 goto fail;
4fbae7d8
MB
106 } else if (port->mode == IPVLAN_MODE_L3S) {
107 /* Old mode was L3S */
108 mdev->priv_flags &= ~IFF_L3MDEV_MASTER;
3133822f 109 ipvlan_unregister_nf_hook(read_pnet(&port->pnet));
4fbae7d8
MB
110 mdev->l3mdev_ops = NULL;
111 }
2ad7bf36
MB
112 port->mode = nval;
113 }
5dc2d399
HL
114 return 0;
115
116fail:
117 /* Undo the flags changes that have been done so far. */
118 list_for_each_entry_continue_reverse(ipvlan, &port->ipvlans, pnode) {
119 flags = ipvlan->dev->flags;
120 if (port->mode == IPVLAN_MODE_L3 ||
121 port->mode == IPVLAN_MODE_L3S)
567c5e13
PM
122 dev_change_flags(ipvlan->dev, flags | IFF_NOARP,
123 NULL);
5dc2d399 124 else
567c5e13
PM
125 dev_change_flags(ipvlan->dev, flags & ~IFF_NOARP,
126 NULL);
5dc2d399
HL
127 }
128
4fbae7d8 129 return err;
2ad7bf36
MB
130}
131
132static int ipvlan_port_create(struct net_device *dev)
133{
134 struct ipvl_port *port;
135 int err, idx;
136
2ad7bf36
MB
137 port = kzalloc(sizeof(struct ipvl_port), GFP_KERNEL);
138 if (!port)
139 return -ENOMEM;
140
3133822f 141 write_pnet(&port->pnet, dev_net(dev));
2ad7bf36
MB
142 port->dev = dev;
143 port->mode = IPVLAN_MODE_L3;
144 INIT_LIST_HEAD(&port->ipvlans);
145 for (idx = 0; idx < IPVLAN_HASH_SIZE; idx++)
146 INIT_HLIST_HEAD(&port->hlhead[idx]);
147
ba35f858
MB
148 skb_queue_head_init(&port->backlog);
149 INIT_WORK(&port->wq, ipvlan_process_multicast);
009146d1 150 ida_init(&port->ida);
da36e13c 151 port->dev_id_start = 1;
ba35f858 152
2ad7bf36
MB
153 err = netdev_rx_handler_register(dev, ipvlan_handle_frame, port);
154 if (err)
155 goto err;
156
2ad7bf36
MB
157 return 0;
158
159err:
48140a21 160 kfree(port);
2ad7bf36
MB
161 return err;
162}
163
164static void ipvlan_port_destroy(struct net_device *dev)
165{
166 struct ipvl_port *port = ipvlan_port_get_rtnl(dev);
b1227d01 167 struct sk_buff *skb;
2ad7bf36 168
4fbae7d8
MB
169 if (port->mode == IPVLAN_MODE_L3S) {
170 dev->priv_flags &= ~IFF_L3MDEV_MASTER;
3133822f 171 ipvlan_unregister_nf_hook(dev_net(dev));
4fbae7d8
MB
172 dev->l3mdev_ops = NULL;
173 }
2ad7bf36 174 netdev_rx_handler_unregister(dev);
ba35f858 175 cancel_work_sync(&port->wq);
b1227d01
ED
176 while ((skb = __skb_dequeue(&port->backlog)) != NULL) {
177 if (skb->dev)
178 dev_put(skb->dev);
179 kfree_skb(skb);
180 }
009146d1 181 ida_destroy(&port->ida);
48140a21 182 kfree(port);
2ad7bf36
MB
183}
184
2ad7bf36 185#define IPVLAN_FEATURES \
a188222b 186 (NETIF_F_SG | NETIF_F_HW_CSUM | NETIF_F_HIGHDMA | NETIF_F_FRAGLIST | \
182e0b6b 187 NETIF_F_GSO | NETIF_F_TSO | NETIF_F_GSO_ROBUST | \
2ad7bf36
MB
188 NETIF_F_TSO_ECN | NETIF_F_TSO6 | NETIF_F_GRO | NETIF_F_RXCSUM | \
189 NETIF_F_HW_VLAN_CTAG_FILTER | NETIF_F_HW_VLAN_STAG_FILTER)
190
191#define IPVLAN_STATE_MASK \
192 ((1<<__LINK_STATE_NOCARRIER) | (1<<__LINK_STATE_DORMANT))
193
2ad7bf36
MB
194static int ipvlan_init(struct net_device *dev)
195{
196 struct ipvl_dev *ipvlan = netdev_priv(dev);
fe18da60
GM
197 struct net_device *phy_dev = ipvlan->phy_dev;
198 struct ipvl_port *port;
199 int err;
2ad7bf36
MB
200
201 dev->state = (dev->state & ~IPVLAN_STATE_MASK) |
202 (phy_dev->state & IPVLAN_STATE_MASK);
203 dev->features = phy_dev->features & IPVLAN_FEATURES;
3518e40b 204 dev->features |= NETIF_F_LLTX | NETIF_F_VLAN_CHALLENGED;
2ad7bf36 205 dev->gso_max_size = phy_dev->gso_max_size;
f6773c5e 206 dev->gso_max_segs = phy_dev->gso_max_segs;
2ad7bf36
MB
207 dev->hard_header_len = phy_dev->hard_header_len;
208
0d7dd798 209 netdev_lockdep_set_classes(dev);
2ad7bf36 210
87173cd6 211 ipvlan->pcpu_stats = netdev_alloc_pcpu_stats(struct ipvl_pcpu_stats);
2ad7bf36
MB
212 if (!ipvlan->pcpu_stats)
213 return -ENOMEM;
214
fe18da60
GM
215 if (!netif_is_ipvlan_port(phy_dev)) {
216 err = ipvlan_port_create(phy_dev);
217 if (err < 0) {
218 free_percpu(ipvlan->pcpu_stats);
219 return err;
220 }
221 }
222 port = ipvlan_port_get_rtnl(phy_dev);
494e8489 223 port->count += 1;
2ad7bf36
MB
224 return 0;
225}
226
227static void ipvlan_uninit(struct net_device *dev)
228{
229 struct ipvl_dev *ipvlan = netdev_priv(dev);
fe18da60
GM
230 struct net_device *phy_dev = ipvlan->phy_dev;
231 struct ipvl_port *port;
2ad7bf36 232
04901cea 233 free_percpu(ipvlan->pcpu_stats);
2ad7bf36 234
fe18da60 235 port = ipvlan_port_get_rtnl(phy_dev);
2ad7bf36
MB
236 port->count -= 1;
237 if (!port->count)
238 ipvlan_port_destroy(port->dev);
239}
240
241static int ipvlan_open(struct net_device *dev)
242{
243 struct ipvl_dev *ipvlan = netdev_priv(dev);
244 struct net_device *phy_dev = ipvlan->phy_dev;
245 struct ipvl_addr *addr;
246
4fbae7d8
MB
247 if (ipvlan->port->mode == IPVLAN_MODE_L3 ||
248 ipvlan->port->mode == IPVLAN_MODE_L3S)
2ad7bf36
MB
249 dev->flags |= IFF_NOARP;
250 else
251 dev->flags &= ~IFF_NOARP;
252
82308194
PA
253 rcu_read_lock();
254 list_for_each_entry_rcu(addr, &ipvlan->addrs, anode)
515866f8 255 ipvlan_ht_addr_add(ipvlan, addr);
82308194 256 rcu_read_unlock();
515866f8 257
2ad7bf36
MB
258 return dev_uc_add(phy_dev, phy_dev->dev_addr);
259}
260
261static int ipvlan_stop(struct net_device *dev)
262{
263 struct ipvl_dev *ipvlan = netdev_priv(dev);
264 struct net_device *phy_dev = ipvlan->phy_dev;
265 struct ipvl_addr *addr;
266
267 dev_uc_unsync(phy_dev, dev);
268 dev_mc_unsync(phy_dev, dev);
269
270 dev_uc_del(phy_dev, phy_dev->dev_addr);
271
82308194
PA
272 rcu_read_lock();
273 list_for_each_entry_rcu(addr, &ipvlan->addrs, anode)
6640e673 274 ipvlan_ht_addr_del(addr);
82308194 275 rcu_read_unlock();
515866f8 276
2ad7bf36
MB
277 return 0;
278}
279
92c7b0de
MB
280static netdev_tx_t ipvlan_start_xmit(struct sk_buff *skb,
281 struct net_device *dev)
2ad7bf36
MB
282{
283 const struct ipvl_dev *ipvlan = netdev_priv(dev);
284 int skblen = skb->len;
285 int ret;
286
287 ret = ipvlan_queue_xmit(skb, dev);
288 if (likely(ret == NET_XMIT_SUCCESS || ret == NET_XMIT_CN)) {
289 struct ipvl_pcpu_stats *pcptr;
290
291 pcptr = this_cpu_ptr(ipvlan->pcpu_stats);
292
293 u64_stats_update_begin(&pcptr->syncp);
294 pcptr->tx_pkts++;
295 pcptr->tx_bytes += skblen;
296 u64_stats_update_end(&pcptr->syncp);
297 } else {
298 this_cpu_inc(ipvlan->pcpu_stats->tx_drps);
299 }
300 return ret;
301}
302
303static netdev_features_t ipvlan_fix_features(struct net_device *dev,
304 netdev_features_t features)
305{
306 struct ipvl_dev *ipvlan = netdev_priv(dev);
307
308 return features & (ipvlan->sfeatures | ~IPVLAN_FEATURES);
309}
310
311static void ipvlan_change_rx_flags(struct net_device *dev, int change)
312{
313 struct ipvl_dev *ipvlan = netdev_priv(dev);
314 struct net_device *phy_dev = ipvlan->phy_dev;
315
316 if (change & IFF_ALLMULTI)
317 dev_set_allmulti(phy_dev, dev->flags & IFF_ALLMULTI? 1 : -1);
318}
319
2ad7bf36
MB
320static void ipvlan_set_multicast_mac_filter(struct net_device *dev)
321{
322 struct ipvl_dev *ipvlan = netdev_priv(dev);
323
324 if (dev->flags & (IFF_PROMISC | IFF_ALLMULTI)) {
325 bitmap_fill(ipvlan->mac_filters, IPVLAN_MAC_FILTER_SIZE);
326 } else {
327 struct netdev_hw_addr *ha;
328 DECLARE_BITMAP(mc_filters, IPVLAN_MAC_FILTER_SIZE);
329
330 bitmap_zero(mc_filters, IPVLAN_MAC_FILTER_SIZE);
331 netdev_for_each_mc_addr(ha, dev)
332 __set_bit(ipvlan_mac_hash(ha->addr), mc_filters);
333
f631c44b
MB
334 /* Turn-on broadcast bit irrespective of address family,
335 * since broadcast is deferred to a work-queue, hence no
336 * impact on fast-path processing.
337 */
338 __set_bit(ipvlan_mac_hash(dev->broadcast), mc_filters);
339
2ad7bf36
MB
340 bitmap_copy(ipvlan->mac_filters, mc_filters,
341 IPVLAN_MAC_FILTER_SIZE);
342 }
343 dev_uc_sync(ipvlan->phy_dev, dev);
344 dev_mc_sync(ipvlan->phy_dev, dev);
345}
346
bc1f4470 347static void ipvlan_get_stats64(struct net_device *dev,
348 struct rtnl_link_stats64 *s)
2ad7bf36
MB
349{
350 struct ipvl_dev *ipvlan = netdev_priv(dev);
351
352 if (ipvlan->pcpu_stats) {
353 struct ipvl_pcpu_stats *pcptr;
354 u64 rx_pkts, rx_bytes, rx_mcast, tx_pkts, tx_bytes;
355 u32 rx_errs = 0, tx_drps = 0;
356 u32 strt;
357 int idx;
358
359 for_each_possible_cpu(idx) {
360 pcptr = per_cpu_ptr(ipvlan->pcpu_stats, idx);
361 do {
362 strt= u64_stats_fetch_begin_irq(&pcptr->syncp);
363 rx_pkts = pcptr->rx_pkts;
364 rx_bytes = pcptr->rx_bytes;
365 rx_mcast = pcptr->rx_mcast;
366 tx_pkts = pcptr->tx_pkts;
367 tx_bytes = pcptr->tx_bytes;
368 } while (u64_stats_fetch_retry_irq(&pcptr->syncp,
369 strt));
370
371 s->rx_packets += rx_pkts;
372 s->rx_bytes += rx_bytes;
373 s->multicast += rx_mcast;
374 s->tx_packets += tx_pkts;
375 s->tx_bytes += tx_bytes;
376
377 /* u32 values are updated without syncp protection. */
378 rx_errs += pcptr->rx_errs;
379 tx_drps += pcptr->tx_drps;
380 }
381 s->rx_errors = rx_errs;
382 s->rx_dropped = rx_errs;
383 s->tx_dropped = tx_drps;
384 }
2ad7bf36
MB
385}
386
387static int ipvlan_vlan_rx_add_vid(struct net_device *dev, __be16 proto, u16 vid)
388{
389 struct ipvl_dev *ipvlan = netdev_priv(dev);
390 struct net_device *phy_dev = ipvlan->phy_dev;
391
392 return vlan_vid_add(phy_dev, proto, vid);
393}
394
395static int ipvlan_vlan_rx_kill_vid(struct net_device *dev, __be16 proto,
396 u16 vid)
397{
398 struct ipvl_dev *ipvlan = netdev_priv(dev);
399 struct net_device *phy_dev = ipvlan->phy_dev;
400
401 vlan_vid_del(phy_dev, proto, vid);
402 return 0;
403}
404
7c411658
ND
405static int ipvlan_get_iflink(const struct net_device *dev)
406{
407 struct ipvl_dev *ipvlan = netdev_priv(dev);
408
409 return ipvlan->phy_dev->ifindex;
410}
411
2ad7bf36
MB
412static const struct net_device_ops ipvlan_netdev_ops = {
413 .ndo_init = ipvlan_init,
414 .ndo_uninit = ipvlan_uninit,
415 .ndo_open = ipvlan_open,
416 .ndo_stop = ipvlan_stop,
417 .ndo_start_xmit = ipvlan_start_xmit,
418 .ndo_fix_features = ipvlan_fix_features,
419 .ndo_change_rx_flags = ipvlan_change_rx_flags,
420 .ndo_set_rx_mode = ipvlan_set_multicast_mac_filter,
421 .ndo_get_stats64 = ipvlan_get_stats64,
422 .ndo_vlan_rx_add_vid = ipvlan_vlan_rx_add_vid,
423 .ndo_vlan_rx_kill_vid = ipvlan_vlan_rx_kill_vid,
7c411658 424 .ndo_get_iflink = ipvlan_get_iflink,
2ad7bf36
MB
425};
426
427static int ipvlan_hard_header(struct sk_buff *skb, struct net_device *dev,
428 unsigned short type, const void *daddr,
429 const void *saddr, unsigned len)
430{
431 const struct ipvl_dev *ipvlan = netdev_priv(dev);
432 struct net_device *phy_dev = ipvlan->phy_dev;
433
434 /* TODO Probably use a different field than dev_addr so that the
435 * mac-address on the virtual device is portable and can be carried
436 * while the packets use the mac-addr on the physical device.
437 */
438 return dev_hard_header(skb, phy_dev, type, daddr,
32c10bbf 439 saddr ? : phy_dev->dev_addr, len);
2ad7bf36
MB
440}
441
442static const struct header_ops ipvlan_header_ops = {
443 .create = ipvlan_hard_header,
2ad7bf36
MB
444 .parse = eth_header_parse,
445 .cache = eth_header_cache,
446 .cache_update = eth_header_cache_update,
447};
448
1ec54cb4
PA
449static bool netif_is_ipvlan(const struct net_device *dev)
450{
451 /* both ipvlan and ipvtap devices use the same netdev_ops */
452 return dev->netdev_ops == &ipvlan_netdev_ops;
453}
454
314d10d7
DD
455static int ipvlan_ethtool_get_link_ksettings(struct net_device *dev,
456 struct ethtool_link_ksettings *cmd)
2ad7bf36
MB
457{
458 const struct ipvl_dev *ipvlan = netdev_priv(dev);
459
314d10d7 460 return __ethtool_get_link_ksettings(ipvlan->phy_dev, cmd);
2ad7bf36
MB
461}
462
463static void ipvlan_ethtool_get_drvinfo(struct net_device *dev,
464 struct ethtool_drvinfo *drvinfo)
465{
466 strlcpy(drvinfo->driver, IPVLAN_DRV, sizeof(drvinfo->driver));
467 strlcpy(drvinfo->version, IPV_DRV_VER, sizeof(drvinfo->version));
468}
469
470static u32 ipvlan_ethtool_get_msglevel(struct net_device *dev)
471{
472 const struct ipvl_dev *ipvlan = netdev_priv(dev);
473
474 return ipvlan->msg_enable;
475}
476
477static void ipvlan_ethtool_set_msglevel(struct net_device *dev, u32 value)
478{
479 struct ipvl_dev *ipvlan = netdev_priv(dev);
480
481 ipvlan->msg_enable = value;
482}
483
484static const struct ethtool_ops ipvlan_ethtool_ops = {
485 .get_link = ethtool_op_get_link,
314d10d7 486 .get_link_ksettings = ipvlan_ethtool_get_link_ksettings,
2ad7bf36
MB
487 .get_drvinfo = ipvlan_ethtool_get_drvinfo,
488 .get_msglevel = ipvlan_ethtool_get_msglevel,
489 .set_msglevel = ipvlan_ethtool_set_msglevel,
490};
491
492static int ipvlan_nl_changelink(struct net_device *dev,
ad744b22
MS
493 struct nlattr *tb[], struct nlattr *data[],
494 struct netlink_ext_ack *extack)
2ad7bf36
MB
495{
496 struct ipvl_dev *ipvlan = netdev_priv(dev);
497 struct ipvl_port *port = ipvlan_port_get_rtnl(ipvlan->phy_dev);
4fbae7d8 498 int err = 0;
2ad7bf36 499
a190d04d
MB
500 if (!data)
501 return 0;
502
503 if (data[IFLA_IPVLAN_MODE]) {
2ad7bf36
MB
504 u16 nmode = nla_get_u16(data[IFLA_IPVLAN_MODE]);
505
cf7686a0 506 err = ipvlan_set_port_mode(port, nmode, extack);
2ad7bf36 507 }
a190d04d
MB
508
509 if (!err && data[IFLA_IPVLAN_FLAGS]) {
510 u16 flags = nla_get_u16(data[IFLA_IPVLAN_FLAGS]);
511
512 if (flags & IPVLAN_F_PRIVATE)
513 ipvlan_mark_private(port);
514 else
515 ipvlan_clear_private(port);
fe89aa6b
MB
516
517 if (flags & IPVLAN_F_VEPA)
518 ipvlan_mark_vepa(port);
519 else
520 ipvlan_clear_vepa(port);
a190d04d
MB
521 }
522
4fbae7d8 523 return err;
2ad7bf36
MB
524}
525
526static size_t ipvlan_nl_getsize(const struct net_device *dev)
527{
528 return (0
529 + nla_total_size(2) /* IFLA_IPVLAN_MODE */
a190d04d 530 + nla_total_size(2) /* IFLA_IPVLAN_FLAGS */
2ad7bf36
MB
531 );
532}
533
a8b8a889
MS
534static int ipvlan_nl_validate(struct nlattr *tb[], struct nlattr *data[],
535 struct netlink_ext_ack *extack)
2ad7bf36 536{
a190d04d
MB
537 if (!data)
538 return 0;
539
540 if (data[IFLA_IPVLAN_MODE]) {
2ad7bf36
MB
541 u16 mode = nla_get_u16(data[IFLA_IPVLAN_MODE]);
542
b1dd054d 543 if (mode >= IPVLAN_MODE_MAX)
2ad7bf36
MB
544 return -EINVAL;
545 }
a190d04d
MB
546 if (data[IFLA_IPVLAN_FLAGS]) {
547 u16 flags = nla_get_u16(data[IFLA_IPVLAN_FLAGS]);
548
fe89aa6b
MB
549 /* Only two bits are used at this moment. */
550 if (flags & ~(IPVLAN_F_PRIVATE | IPVLAN_F_VEPA))
551 return -EINVAL;
552 /* Also both flags can't be active at the same time. */
553 if ((flags & (IPVLAN_F_PRIVATE | IPVLAN_F_VEPA)) ==
554 (IPVLAN_F_PRIVATE | IPVLAN_F_VEPA))
a190d04d
MB
555 return -EINVAL;
556 }
557
2ad7bf36
MB
558 return 0;
559}
560
561static int ipvlan_nl_fillinfo(struct sk_buff *skb,
562 const struct net_device *dev)
563{
564 struct ipvl_dev *ipvlan = netdev_priv(dev);
565 struct ipvl_port *port = ipvlan_port_get_rtnl(ipvlan->phy_dev);
566 int ret = -EINVAL;
567
568 if (!port)
569 goto err;
570
571 ret = -EMSGSIZE;
572 if (nla_put_u16(skb, IFLA_IPVLAN_MODE, port->mode))
573 goto err;
a190d04d
MB
574 if (nla_put_u16(skb, IFLA_IPVLAN_FLAGS, port->flags))
575 goto err;
2ad7bf36
MB
576
577 return 0;
578
579err:
580 return ret;
581}
582
235a9d89 583int ipvlan_link_new(struct net *src_net, struct net_device *dev,
7a3f4a18
MS
584 struct nlattr *tb[], struct nlattr *data[],
585 struct netlink_ext_ack *extack)
2ad7bf36
MB
586{
587 struct ipvl_dev *ipvlan = netdev_priv(dev);
588 struct ipvl_port *port;
589 struct net_device *phy_dev;
590 int err;
e93fbc5a 591 u16 mode = IPVLAN_MODE_L3;
2ad7bf36
MB
592
593 if (!tb[IFLA_LINK])
594 return -EINVAL;
595
596 phy_dev = __dev_get_by_index(src_net, nla_get_u32(tb[IFLA_LINK]));
597 if (!phy_dev)
598 return -ENODEV;
599
5933fea7 600 if (netif_is_ipvlan(phy_dev)) {
2ad7bf36
MB
601 struct ipvl_dev *tmp = netdev_priv(phy_dev);
602
603 phy_dev = tmp->phy_dev;
5933fea7 604 } else if (!netif_is_ipvlan_port(phy_dev)) {
fe18da60
GM
605 /* Exit early if the underlying link is invalid or busy */
606 if (phy_dev->type != ARPHRD_ETHER ||
607 phy_dev->flags & IFF_LOOPBACK) {
608 netdev_err(phy_dev,
609 "Master is either lo or non-ether device\n");
610 return -EINVAL;
611 }
2ad7bf36 612
fe18da60
GM
613 if (netdev_is_rx_handler_busy(phy_dev)) {
614 netdev_err(phy_dev, "Device is already in use.\n");
615 return -EBUSY;
616 }
617 }
2ad7bf36
MB
618
619 ipvlan->phy_dev = phy_dev;
620 ipvlan->dev = dev;
2ad7bf36 621 ipvlan->sfeatures = IPVLAN_FEATURES;
30877961
XL
622 if (!tb[IFLA_MTU])
623 ipvlan_adjust_mtu(ipvlan, phy_dev);
2ad7bf36 624 INIT_LIST_HEAD(&ipvlan->addrs);
82308194 625 spin_lock_init(&ipvlan->addrs_lock);
2ad7bf36 626
fe18da60
GM
627 /* TODO Probably put random address here to be presented to the
628 * world but keep using the physical-dev address for the outgoing
629 * packets.
a190d04d 630 */
fe18da60
GM
631 memcpy(dev->dev_addr, phy_dev->dev_addr, ETH_ALEN);
632
f5426250
PA
633 dev->priv_flags |= IFF_NO_RX_HANDLER;
634
fe18da60
GM
635 err = register_netdevice(dev);
636 if (err < 0)
637 return err;
638
639 /* ipvlan_init() would have created the port, if required */
640 port = ipvlan_port_get_rtnl(phy_dev);
641 ipvlan->port = port;
a190d04d 642
da36e13c
MB
643 /* If the port-id base is at the MAX value, then wrap it around and
644 * begin from 0x1 again. This may be due to a busy system where lots
645 * of slaves are getting created and deleted.
646 */
647 if (port->dev_id_start == 0xFFFE)
648 port->dev_id_start = 0x1;
649
009146d1
MB
650 /* Since L2 address is shared among all IPvlan slaves including
651 * master, use unique 16 bit dev-ids to diffentiate among them.
652 * Assign IDs between 0x1 and 0xFFFE (used by the master) to each
653 * slave link [see addrconf_ifid_eui48()].
654 */
da36e13c
MB
655 err = ida_simple_get(&port->ida, port->dev_id_start, 0xFFFE,
656 GFP_KERNEL);
019ec003
MB
657 if (err < 0)
658 err = ida_simple_get(&port->ida, 0x1, port->dev_id_start,
659 GFP_KERNEL);
009146d1 660 if (err < 0)
fe18da60 661 goto unregister_netdev;
009146d1 662 dev->dev_id = err;
fe18da60 663
da36e13c
MB
664 /* Increment id-base to the next slot for the future assignment */
665 port->dev_id_start = err + 1;
009146d1 666
fe18da60
GM
667 err = netdev_upper_dev_link(phy_dev, dev, extack);
668 if (err)
669 goto remove_ida;
2ad7bf36 670
fe18da60
GM
671 /* Flags are per port and latest update overrides. User has
672 * to be consistent in setting it just like the mode attribute.
673 */
674 if (data && data[IFLA_IPVLAN_FLAGS])
675 port->flags = nla_get_u16(data[IFLA_IPVLAN_FLAGS]);
2ad7bf36 676
fe18da60
GM
677 if (data && data[IFLA_IPVLAN_MODE])
678 mode = nla_get_u16(data[IFLA_IPVLAN_MODE]);
2ad7bf36 679
cf7686a0 680 err = ipvlan_set_port_mode(port, mode, extack);
fe18da60 681 if (err)
1a31cc86 682 goto unlink_netdev;
2ad7bf36
MB
683
684 list_add_tail_rcu(&ipvlan->pnode, &port->ipvlans);
685 netif_stacked_transfer_operstate(phy_dev, dev);
686 return 0;
147fd287 687
1a31cc86
GF
688unlink_netdev:
689 netdev_upper_dev_unlink(phy_dev, dev);
009146d1
MB
690remove_ida:
691 ida_simple_remove(&port->ida, dev->dev_id);
fe18da60
GM
692unregister_netdev:
693 unregister_netdevice(dev);
147fd287 694 return err;
2ad7bf36 695}
235a9d89 696EXPORT_SYMBOL_GPL(ipvlan_link_new);
2ad7bf36 697
235a9d89 698void ipvlan_link_delete(struct net_device *dev, struct list_head *head)
2ad7bf36
MB
699{
700 struct ipvl_dev *ipvlan = netdev_priv(dev);
701 struct ipvl_addr *addr, *next;
702
82308194 703 spin_lock_bh(&ipvlan->addrs_lock);
515866f8 704 list_for_each_entry_safe(addr, next, &ipvlan->addrs, anode) {
6640e673 705 ipvlan_ht_addr_del(addr);
82308194 706 list_del_rcu(&addr->anode);
6a725497 707 kfree_rcu(addr, rcu);
2ad7bf36 708 }
82308194 709 spin_unlock_bh(&ipvlan->addrs_lock);
515866f8 710
009146d1 711 ida_simple_remove(&ipvlan->port->ida, dev->dev_id);
2ad7bf36
MB
712 list_del_rcu(&ipvlan->pnode);
713 unregister_netdevice_queue(dev, head);
714 netdev_upper_dev_unlink(ipvlan->phy_dev, dev);
715}
235a9d89 716EXPORT_SYMBOL_GPL(ipvlan_link_delete);
2ad7bf36 717
235a9d89 718void ipvlan_link_setup(struct net_device *dev)
2ad7bf36
MB
719{
720 ether_setup(dev);
721
548feb33 722 dev->max_mtu = ETH_MAX_MTU;
2ad7bf36 723 dev->priv_flags &= ~(IFF_XMIT_DST_RELEASE | IFF_TX_SKB_SHARING);
bf485bcf 724 dev->priv_flags |= IFF_UNICAST_FLT | IFF_NO_QUEUE;
2ad7bf36 725 dev->netdev_ops = &ipvlan_netdev_ops;
cf124db5 726 dev->needs_free_netdev = true;
2ad7bf36
MB
727 dev->header_ops = &ipvlan_header_ops;
728 dev->ethtool_ops = &ipvlan_ethtool_ops;
2ad7bf36 729}
235a9d89 730EXPORT_SYMBOL_GPL(ipvlan_link_setup);
2ad7bf36
MB
731
732static const struct nla_policy ipvlan_nl_policy[IFLA_IPVLAN_MAX + 1] =
733{
734 [IFLA_IPVLAN_MODE] = { .type = NLA_U16 },
a190d04d 735 [IFLA_IPVLAN_FLAGS] = { .type = NLA_U16 },
2ad7bf36
MB
736};
737
738static struct rtnl_link_ops ipvlan_link_ops = {
739 .kind = "ipvlan",
740 .priv_size = sizeof(struct ipvl_dev),
741
2ad7bf36
MB
742 .setup = ipvlan_link_setup,
743 .newlink = ipvlan_link_new,
744 .dellink = ipvlan_link_delete,
745};
746
235a9d89 747int ipvlan_link_register(struct rtnl_link_ops *ops)
2ad7bf36 748{
235a9d89
SG
749 ops->get_size = ipvlan_nl_getsize;
750 ops->policy = ipvlan_nl_policy;
751 ops->validate = ipvlan_nl_validate;
752 ops->fill_info = ipvlan_nl_fillinfo;
753 ops->changelink = ipvlan_nl_changelink;
754 ops->maxtype = IFLA_IPVLAN_MAX;
2ad7bf36
MB
755 return rtnl_link_register(ops);
756}
235a9d89 757EXPORT_SYMBOL_GPL(ipvlan_link_register);
2ad7bf36
MB
758
759static int ipvlan_device_event(struct notifier_block *unused,
760 unsigned long event, void *ptr)
761{
762 struct net_device *dev = netdev_notifier_info_to_dev(ptr);
763 struct ipvl_dev *ipvlan, *next;
764 struct ipvl_port *port;
765 LIST_HEAD(lst_kill);
766
5933fea7 767 if (!netif_is_ipvlan_port(dev))
2ad7bf36
MB
768 return NOTIFY_DONE;
769
770 port = ipvlan_port_get_rtnl(dev);
771
772 switch (event) {
773 case NETDEV_CHANGE:
774 list_for_each_entry(ipvlan, &port->ipvlans, pnode)
775 netif_stacked_transfer_operstate(ipvlan->phy_dev,
776 ipvlan->dev);
777 break;
778
3133822f
FW
779 case NETDEV_REGISTER: {
780 struct net *oldnet, *newnet = dev_net(dev);
781 struct ipvlan_netns *old_vnet;
782
783 oldnet = read_pnet(&port->pnet);
784 if (net_eq(newnet, oldnet))
785 break;
786
787 write_pnet(&port->pnet, newnet);
788
789 old_vnet = net_generic(oldnet, ipvlan_netid);
790 if (!old_vnet->ipvl_nf_hook_refcnt)
791 break;
792
793 ipvlan_register_nf_hook(newnet);
794 ipvlan_unregister_nf_hook(oldnet);
795 break;
796 }
2ad7bf36
MB
797 case NETDEV_UNREGISTER:
798 if (dev->reg_state != NETREG_UNREGISTERING)
799 break;
800
82308194 801 list_for_each_entry_safe(ipvlan, next, &port->ipvlans, pnode)
2ad7bf36
MB
802 ipvlan->dev->rtnl_link_ops->dellink(ipvlan->dev,
803 &lst_kill);
804 unregister_netdevice_many(&lst_kill);
805 break;
806
807 case NETDEV_FEAT_CHANGE:
808 list_for_each_entry(ipvlan, &port->ipvlans, pnode) {
809 ipvlan->dev->features = dev->features & IPVLAN_FEATURES;
810 ipvlan->dev->gso_max_size = dev->gso_max_size;
f6773c5e 811 ipvlan->dev->gso_max_segs = dev->gso_max_segs;
2ad7bf36
MB
812 netdev_features_change(ipvlan->dev);
813 }
814 break;
815
816 case NETDEV_CHANGEMTU:
817 list_for_each_entry(ipvlan, &port->ipvlans, pnode)
818 ipvlan_adjust_mtu(ipvlan, dev);
819 break;
820
32c10bbf 821 case NETDEV_CHANGEADDR:
ab452c3c 822 list_for_each_entry(ipvlan, &port->ipvlans, pnode) {
32c10bbf 823 ether_addr_copy(ipvlan->dev->dev_addr, dev->dev_addr);
ab452c3c
KL
824 call_netdevice_notifiers(NETDEV_CHANGEADDR, ipvlan->dev);
825 }
32c10bbf
MB
826 break;
827
2ad7bf36
MB
828 case NETDEV_PRE_TYPE_CHANGE:
829 /* Forbid underlying device to change its type. */
830 return NOTIFY_BAD;
831 }
832 return NOTIFY_DONE;
833}
834
82308194 835/* the caller must held the addrs lock */
86673982 836static int ipvlan_add_addr(struct ipvl_dev *ipvlan, void *iaddr, bool is_v6)
2ad7bf36
MB
837{
838 struct ipvl_addr *addr;
839
2ad7bf36
MB
840 addr = kzalloc(sizeof(struct ipvl_addr), GFP_ATOMIC);
841 if (!addr)
842 return -ENOMEM;
843
844 addr->master = ipvlan;
94333fac 845 if (!is_v6) {
86673982
GF
846 memcpy(&addr->ip4addr, iaddr, sizeof(struct in_addr));
847 addr->atype = IPVL_IPV4;
94333fac
MC
848#if IS_ENABLED(CONFIG_IPV6)
849 } else {
850 memcpy(&addr->ip6addr, iaddr, sizeof(struct in6_addr));
851 addr->atype = IPVL_IPV6;
852#endif
86673982 853 }
82308194
PA
854
855 list_add_tail_rcu(&addr->anode, &ipvlan->addrs);
515866f8 856
27705f70
JB
857 /* If the interface is not up, the address will be added to the hash
858 * list by ipvlan_open.
859 */
860 if (netif_running(ipvlan->dev))
861 ipvlan_ht_addr_add(ipvlan, addr);
2ad7bf36
MB
862
863 return 0;
864}
865
86673982 866static void ipvlan_del_addr(struct ipvl_dev *ipvlan, void *iaddr, bool is_v6)
2ad7bf36
MB
867{
868 struct ipvl_addr *addr;
869
82308194 870 spin_lock_bh(&ipvlan->addrs_lock);
86673982 871 addr = ipvlan_find_addr(ipvlan, iaddr, is_v6);
82308194
PA
872 if (!addr) {
873 spin_unlock_bh(&ipvlan->addrs_lock);
2ad7bf36 874 return;
82308194 875 }
2ad7bf36 876
6640e673 877 ipvlan_ht_addr_del(addr);
82308194
PA
878 list_del_rcu(&addr->anode);
879 spin_unlock_bh(&ipvlan->addrs_lock);
2ad7bf36 880 kfree_rcu(addr, rcu);
2ad7bf36
MB
881}
882
94333fac
MC
883static bool ipvlan_is_valid_dev(const struct net_device *dev)
884{
885 struct ipvl_dev *ipvlan = netdev_priv(dev);
886
887 if (!netif_is_ipvlan(dev))
888 return false;
889
890 if (!ipvlan || !ipvlan->port)
891 return false;
892
893 return true;
894}
895
896#if IS_ENABLED(CONFIG_IPV6)
86673982
GF
897static int ipvlan_add_addr6(struct ipvl_dev *ipvlan, struct in6_addr *ip6_addr)
898{
82308194
PA
899 int ret = -EINVAL;
900
901 spin_lock_bh(&ipvlan->addrs_lock);
902 if (ipvlan_addr_busy(ipvlan->port, ip6_addr, true))
86673982
GF
903 netif_err(ipvlan, ifup, ipvlan->dev,
904 "Failed to add IPv6=%pI6c addr for %s intf\n",
905 ip6_addr, ipvlan->dev->name);
82308194
PA
906 else
907 ret = ipvlan_add_addr(ipvlan, ip6_addr, true);
908 spin_unlock_bh(&ipvlan->addrs_lock);
909 return ret;
86673982
GF
910}
911
912static void ipvlan_del_addr6(struct ipvl_dev *ipvlan, struct in6_addr *ip6_addr)
913{
914 return ipvlan_del_addr(ipvlan, ip6_addr, true);
915}
916
2ad7bf36
MB
917static int ipvlan_addr6_event(struct notifier_block *unused,
918 unsigned long event, void *ptr)
919{
920 struct inet6_ifaddr *if6 = (struct inet6_ifaddr *)ptr;
921 struct net_device *dev = (struct net_device *)if6->idev->dev;
922 struct ipvl_dev *ipvlan = netdev_priv(dev);
923
5e51fe6f 924 if (!ipvlan_is_valid_dev(dev))
2ad7bf36
MB
925 return NOTIFY_DONE;
926
927 switch (event) {
928 case NETDEV_UP:
929 if (ipvlan_add_addr6(ipvlan, &if6->addr))
930 return NOTIFY_BAD;
931 break;
932
933 case NETDEV_DOWN:
934 ipvlan_del_addr6(ipvlan, &if6->addr);
935 break;
936 }
937
938 return NOTIFY_OK;
939}
940
3ad7d246
KJ
941static int ipvlan_addr6_validator_event(struct notifier_block *unused,
942 unsigned long event, void *ptr)
943{
944 struct in6_validator_info *i6vi = (struct in6_validator_info *)ptr;
945 struct net_device *dev = (struct net_device *)i6vi->i6vi_dev->dev;
946 struct ipvl_dev *ipvlan = netdev_priv(dev);
947
5e51fe6f 948 if (!ipvlan_is_valid_dev(dev))
3ad7d246
KJ
949 return NOTIFY_DONE;
950
951 switch (event) {
952 case NETDEV_UP:
de95e047
DA
953 if (ipvlan_addr_busy(ipvlan->port, &i6vi->i6vi_addr, true)) {
954 NL_SET_ERR_MSG(i6vi->extack,
955 "Address already assigned to an ipvlan device");
3ad7d246 956 return notifier_from_errno(-EADDRINUSE);
de95e047 957 }
3ad7d246
KJ
958 break;
959 }
960
961 return NOTIFY_OK;
962}
94333fac 963#endif
3ad7d246 964
2ad7bf36
MB
965static int ipvlan_add_addr4(struct ipvl_dev *ipvlan, struct in_addr *ip4_addr)
966{
82308194
PA
967 int ret = -EINVAL;
968
969 spin_lock_bh(&ipvlan->addrs_lock);
970 if (ipvlan_addr_busy(ipvlan->port, ip4_addr, false))
2ad7bf36
MB
971 netif_err(ipvlan, ifup, ipvlan->dev,
972 "Failed to add IPv4=%pI4 on %s intf.\n",
973 ip4_addr, ipvlan->dev->name);
82308194
PA
974 else
975 ret = ipvlan_add_addr(ipvlan, ip4_addr, false);
976 spin_unlock_bh(&ipvlan->addrs_lock);
977 return ret;
2ad7bf36
MB
978}
979
980static void ipvlan_del_addr4(struct ipvl_dev *ipvlan, struct in_addr *ip4_addr)
981{
86673982 982 return ipvlan_del_addr(ipvlan, ip4_addr, false);
2ad7bf36
MB
983}
984
985static int ipvlan_addr4_event(struct notifier_block *unused,
986 unsigned long event, void *ptr)
987{
988 struct in_ifaddr *if4 = (struct in_ifaddr *)ptr;
989 struct net_device *dev = (struct net_device *)if4->ifa_dev->dev;
990 struct ipvl_dev *ipvlan = netdev_priv(dev);
991 struct in_addr ip4_addr;
992
5e51fe6f 993 if (!ipvlan_is_valid_dev(dev))
2ad7bf36
MB
994 return NOTIFY_DONE;
995
996 switch (event) {
997 case NETDEV_UP:
998 ip4_addr.s_addr = if4->ifa_address;
999 if (ipvlan_add_addr4(ipvlan, &ip4_addr))
1000 return NOTIFY_BAD;
1001 break;
1002
1003 case NETDEV_DOWN:
1004 ip4_addr.s_addr = if4->ifa_address;
1005 ipvlan_del_addr4(ipvlan, &ip4_addr);
1006 break;
1007 }
1008
1009 return NOTIFY_OK;
1010}
1011
3ad7d246
KJ
1012static int ipvlan_addr4_validator_event(struct notifier_block *unused,
1013 unsigned long event, void *ptr)
1014{
1015 struct in_validator_info *ivi = (struct in_validator_info *)ptr;
1016 struct net_device *dev = (struct net_device *)ivi->ivi_dev->dev;
1017 struct ipvl_dev *ipvlan = netdev_priv(dev);
1018
5e51fe6f 1019 if (!ipvlan_is_valid_dev(dev))
3ad7d246
KJ
1020 return NOTIFY_DONE;
1021
1022 switch (event) {
1023 case NETDEV_UP:
de95e047
DA
1024 if (ipvlan_addr_busy(ipvlan->port, &ivi->ivi_addr, false)) {
1025 NL_SET_ERR_MSG(ivi->extack,
1026 "Address already assigned to an ipvlan device");
3ad7d246 1027 return notifier_from_errno(-EADDRINUSE);
de95e047 1028 }
3ad7d246
KJ
1029 break;
1030 }
1031
1032 return NOTIFY_OK;
1033}
1034
2ad7bf36
MB
1035static struct notifier_block ipvlan_addr4_notifier_block __read_mostly = {
1036 .notifier_call = ipvlan_addr4_event,
1037};
1038
3ad7d246
KJ
1039static struct notifier_block ipvlan_addr4_vtor_notifier_block __read_mostly = {
1040 .notifier_call = ipvlan_addr4_validator_event,
1041};
1042
2ad7bf36
MB
1043static struct notifier_block ipvlan_notifier_block __read_mostly = {
1044 .notifier_call = ipvlan_device_event,
1045};
1046
94333fac 1047#if IS_ENABLED(CONFIG_IPV6)
2ad7bf36
MB
1048static struct notifier_block ipvlan_addr6_notifier_block __read_mostly = {
1049 .notifier_call = ipvlan_addr6_event,
1050};
1051
3ad7d246
KJ
1052static struct notifier_block ipvlan_addr6_vtor_notifier_block __read_mostly = {
1053 .notifier_call = ipvlan_addr6_validator_event,
1054};
94333fac 1055#endif
3ad7d246 1056
3133822f
FW
1057static void ipvlan_ns_exit(struct net *net)
1058{
1059 struct ipvlan_netns *vnet = net_generic(net, ipvlan_netid);
1060
1061 if (WARN_ON_ONCE(vnet->ipvl_nf_hook_refcnt)) {
1062 vnet->ipvl_nf_hook_refcnt = 0;
1063 nf_unregister_net_hooks(net, ipvl_nfops,
1064 ARRAY_SIZE(ipvl_nfops));
1065 }
1066}
1067
1068static struct pernet_operations ipvlan_net_ops = {
1069 .id = &ipvlan_netid,
1070 .size = sizeof(struct ipvlan_netns),
1071 .exit = ipvlan_ns_exit,
1072};
1073
2ad7bf36
MB
1074static int __init ipvlan_init_module(void)
1075{
1076 int err;
1077
1078 ipvlan_init_secret();
1079 register_netdevice_notifier(&ipvlan_notifier_block);
94333fac 1080#if IS_ENABLED(CONFIG_IPV6)
2ad7bf36 1081 register_inet6addr_notifier(&ipvlan_addr6_notifier_block);
3ad7d246
KJ
1082 register_inet6addr_validator_notifier(
1083 &ipvlan_addr6_vtor_notifier_block);
94333fac 1084#endif
2ad7bf36 1085 register_inetaddr_notifier(&ipvlan_addr4_notifier_block);
3ad7d246 1086 register_inetaddr_validator_notifier(&ipvlan_addr4_vtor_notifier_block);
2ad7bf36 1087
3133822f 1088 err = register_pernet_subsys(&ipvlan_net_ops);
2ad7bf36
MB
1089 if (err < 0)
1090 goto error;
1091
3133822f
FW
1092 err = ipvlan_link_register(&ipvlan_link_ops);
1093 if (err < 0) {
1094 unregister_pernet_subsys(&ipvlan_net_ops);
1095 goto error;
1096 }
1097
2ad7bf36
MB
1098 return 0;
1099error:
1100 unregister_inetaddr_notifier(&ipvlan_addr4_notifier_block);
3ad7d246
KJ
1101 unregister_inetaddr_validator_notifier(
1102 &ipvlan_addr4_vtor_notifier_block);
94333fac 1103#if IS_ENABLED(CONFIG_IPV6)
2ad7bf36 1104 unregister_inet6addr_notifier(&ipvlan_addr6_notifier_block);
3ad7d246
KJ
1105 unregister_inet6addr_validator_notifier(
1106 &ipvlan_addr6_vtor_notifier_block);
94333fac 1107#endif
2ad7bf36
MB
1108 unregister_netdevice_notifier(&ipvlan_notifier_block);
1109 return err;
1110}
1111
1112static void __exit ipvlan_cleanup_module(void)
1113{
1114 rtnl_link_unregister(&ipvlan_link_ops);
3133822f 1115 unregister_pernet_subsys(&ipvlan_net_ops);
2ad7bf36
MB
1116 unregister_netdevice_notifier(&ipvlan_notifier_block);
1117 unregister_inetaddr_notifier(&ipvlan_addr4_notifier_block);
3ad7d246
KJ
1118 unregister_inetaddr_validator_notifier(
1119 &ipvlan_addr4_vtor_notifier_block);
94333fac 1120#if IS_ENABLED(CONFIG_IPV6)
2ad7bf36 1121 unregister_inet6addr_notifier(&ipvlan_addr6_notifier_block);
3ad7d246
KJ
1122 unregister_inet6addr_validator_notifier(
1123 &ipvlan_addr6_vtor_notifier_block);
94333fac 1124#endif
2ad7bf36
MB
1125}
1126
1127module_init(ipvlan_init_module);
1128module_exit(ipvlan_cleanup_module);
1129
1130MODULE_LICENSE("GPL");
1131MODULE_AUTHOR("Mahesh Bandewar <maheshb@google.com>");
1132MODULE_DESCRIPTION("Driver for L3 (IPv6/IPv4) based VLANs");
1133MODULE_ALIAS_RTNL_LINK("ipvlan");