Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[VLAN]: Introduce the vlan_net structure and init/exit net ops.

Unlike TUN, it is empty from the very beginning, and will
be eventually populated later.

Signed-off-by: Pavel Emelyanov <xemul@openvz.org>
Acked-by: Patrick McHardy <kaber@trash.net>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Pavel Emelyanov and committed by
David S. Miller
d9ed0f0e a9fde260

+51
+46
net/8021q/vlan.c
··· 32 32 #include <linux/rtnetlink.h> 33 33 #include <linux/notifier.h> 34 34 #include <net/net_namespace.h> 35 + #include <net/netns/generic.h> 35 36 36 37 #include <linux/if_vlan.h> 37 38 #include "vlan.h" ··· 41 40 #define DRV_VERSION "1.8" 42 41 43 42 /* Global VLAN variables */ 43 + 44 + int vlan_net_id; 44 45 45 46 /* Our listing of VLAN group(s) */ 46 47 static struct hlist_head vlan_group_hash[VLAN_GRP_HASH_SIZE]; ··· 628 625 return err; 629 626 } 630 627 628 + static int vlan_init_net(struct net *net) 629 + { 630 + int err; 631 + struct vlan_net *vn; 632 + 633 + err = -ENOMEM; 634 + vn = kzalloc(sizeof(struct vlan_net), GFP_KERNEL); 635 + if (vn == NULL) 636 + goto err_alloc; 637 + 638 + err = net_assign_generic(net, vlan_net_id, vn); 639 + if (err < 0) 640 + goto err_assign; 641 + 642 + return 0; 643 + 644 + err_assign: 645 + kfree(vn); 646 + err_alloc: 647 + return err; 648 + } 649 + 650 + static void vlan_exit_net(struct net *net) 651 + { 652 + struct vlan_net *vn; 653 + 654 + vn = net_generic(net, vlan_net_id); 655 + kfree(vn); 656 + } 657 + 658 + static struct pernet_operations vlan_net_ops = { 659 + .init = vlan_init_net, 660 + .exit = vlan_exit_net, 661 + }; 662 + 631 663 static int __init vlan_proto_init(void) 632 664 { 633 665 int err; 634 666 635 667 pr_info("%s v%s %s\n", vlan_fullname, vlan_version, vlan_copyright); 636 668 pr_info("All bugs added by %s\n", vlan_buggyright); 669 + 670 + err = register_pernet_gen_device(&vlan_net_id, &vlan_net_ops); 671 + if (err < 0) 672 + goto err0; 637 673 638 674 err = vlan_proc_init(); 639 675 if (err < 0) ··· 695 653 err2: 696 654 vlan_proc_cleanup(); 697 655 err1: 656 + unregister_pernet_gen_device(vlan_net_id, &vlan_net_ops); 657 + err0: 698 658 return err; 699 659 } 700 660 ··· 716 672 BUG_ON(!hlist_empty(&vlan_group_hash[i])); 717 673 718 674 vlan_proc_cleanup(); 675 + 676 + unregister_pernet_gen_device(vlan_net_id, &vlan_net_ops); 719 677 720 678 synchronize_net(); 721 679 }
+5
net/8021q/vlan.h
··· 50 50 return dev->priv_flags & IFF_802_1Q_VLAN; 51 51 } 52 52 53 + extern int vlan_net_id; 54 + 55 + struct vlan_net { 56 + }; 57 + 53 58 #endif /* !(__BEN_VLAN_802_1Q_INC__) */