diff options
author | Matteo Croce <mcroce@redhat.com> | 2018-02-20 19:31:13 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2018-02-21 17:50:57 -0500 |
commit | 94333fac44d1da19ebdf41704780c1af3cabea61 (patch) | |
tree | 7736c274474f4c93578cd0f4676cf40381b20866 /drivers/net/ipvlan/ipvlan_main.c | |
parent | cac56209a66ea3b0be67aa2966b2c628b944da1e (diff) |
ipvlan: drop ipv6 dependency
IPVlan has an hard dependency on IPv6, refactor the ipvlan code to allow
compiling it with IPv6 disabled, move duplicate code into addr_equal()
and refactor series of if-else into a switch.
Signed-off-by: Matteo Croce <mcroce@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/ipvlan/ipvlan_main.c')
-rw-r--r-- | drivers/net/ipvlan/ipvlan_main.c | 48 |
1 files changed, 31 insertions, 17 deletions
diff --git a/drivers/net/ipvlan/ipvlan_main.c b/drivers/net/ipvlan/ipvlan_main.c index 2469df118fbf..67c91ceda979 100644 --- a/drivers/net/ipvlan/ipvlan_main.c +++ b/drivers/net/ipvlan/ipvlan_main.c | |||
@@ -22,12 +22,14 @@ static const struct nf_hook_ops ipvl_nfops[] = { | |||
22 | .hooknum = NF_INET_LOCAL_IN, | 22 | .hooknum = NF_INET_LOCAL_IN, |
23 | .priority = INT_MAX, | 23 | .priority = INT_MAX, |
24 | }, | 24 | }, |
25 | #if IS_ENABLED(CONFIG_IPV6) | ||
25 | { | 26 | { |
26 | .hook = ipvlan_nf_input, | 27 | .hook = ipvlan_nf_input, |
27 | .pf = NFPROTO_IPV6, | 28 | .pf = NFPROTO_IPV6, |
28 | .hooknum = NF_INET_LOCAL_IN, | 29 | .hooknum = NF_INET_LOCAL_IN, |
29 | .priority = INT_MAX, | 30 | .priority = INT_MAX, |
30 | }, | 31 | }, |
32 | #endif | ||
31 | }; | 33 | }; |
32 | 34 | ||
33 | static const struct l3mdev_ops ipvl_l3mdev_ops = { | 35 | static const struct l3mdev_ops ipvl_l3mdev_ops = { |
@@ -800,12 +802,14 @@ static int ipvlan_add_addr(struct ipvl_dev *ipvlan, void *iaddr, bool is_v6) | |||
800 | return -ENOMEM; | 802 | return -ENOMEM; |
801 | 803 | ||
802 | addr->master = ipvlan; | 804 | addr->master = ipvlan; |
803 | if (is_v6) { | 805 | if (!is_v6) { |
804 | memcpy(&addr->ip6addr, iaddr, sizeof(struct in6_addr)); | ||
805 | addr->atype = IPVL_IPV6; | ||
806 | } else { | ||
807 | memcpy(&addr->ip4addr, iaddr, sizeof(struct in_addr)); | 806 | memcpy(&addr->ip4addr, iaddr, sizeof(struct in_addr)); |
808 | addr->atype = IPVL_IPV4; | 807 | addr->atype = IPVL_IPV4; |
808 | #if IS_ENABLED(CONFIG_IPV6) | ||
809 | } else { | ||
810 | memcpy(&addr->ip6addr, iaddr, sizeof(struct in6_addr)); | ||
811 | addr->atype = IPVL_IPV6; | ||
812 | #endif | ||
809 | } | 813 | } |
810 | list_add_tail(&addr->anode, &ipvlan->addrs); | 814 | list_add_tail(&addr->anode, &ipvlan->addrs); |
811 | 815 | ||
@@ -833,6 +837,20 @@ static void ipvlan_del_addr(struct ipvl_dev *ipvlan, void *iaddr, bool is_v6) | |||
833 | return; | 837 | return; |
834 | } | 838 | } |
835 | 839 | ||
840 | static bool ipvlan_is_valid_dev(const struct net_device *dev) | ||
841 | { | ||
842 | struct ipvl_dev *ipvlan = netdev_priv(dev); | ||
843 | |||
844 | if (!netif_is_ipvlan(dev)) | ||
845 | return false; | ||
846 | |||
847 | if (!ipvlan || !ipvlan->port) | ||
848 | return false; | ||
849 | |||
850 | return true; | ||
851 | } | ||
852 | |||
853 | #if IS_ENABLED(CONFIG_IPV6) | ||
836 | static int ipvlan_add_addr6(struct ipvl_dev *ipvlan, struct in6_addr *ip6_addr) | 854 | static int ipvlan_add_addr6(struct ipvl_dev *ipvlan, struct in6_addr *ip6_addr) |
837 | { | 855 | { |
838 | if (ipvlan_addr_busy(ipvlan->port, ip6_addr, true)) { | 856 | if (ipvlan_addr_busy(ipvlan->port, ip6_addr, true)) { |
@@ -850,19 +868,6 @@ static void ipvlan_del_addr6(struct ipvl_dev *ipvlan, struct in6_addr *ip6_addr) | |||
850 | return ipvlan_del_addr(ipvlan, ip6_addr, true); | 868 | return ipvlan_del_addr(ipvlan, ip6_addr, true); |
851 | } | 869 | } |
852 | 870 | ||
853 | static bool ipvlan_is_valid_dev(const struct net_device *dev) | ||
854 | { | ||
855 | struct ipvl_dev *ipvlan = netdev_priv(dev); | ||
856 | |||
857 | if (!netif_is_ipvlan(dev)) | ||
858 | return false; | ||
859 | |||
860 | if (!ipvlan || !ipvlan->port) | ||
861 | return false; | ||
862 | |||
863 | return true; | ||
864 | } | ||
865 | |||
866 | static int ipvlan_addr6_event(struct notifier_block *unused, | 871 | static int ipvlan_addr6_event(struct notifier_block *unused, |
867 | unsigned long event, void *ptr) | 872 | unsigned long event, void *ptr) |
868 | { | 873 | { |
@@ -913,6 +918,7 @@ static int ipvlan_addr6_validator_event(struct notifier_block *unused, | |||
913 | 918 | ||
914 | return NOTIFY_OK; | 919 | return NOTIFY_OK; |
915 | } | 920 | } |
921 | #endif | ||
916 | 922 | ||
917 | static int ipvlan_add_addr4(struct ipvl_dev *ipvlan, struct in_addr *ip4_addr) | 923 | static int ipvlan_add_addr4(struct ipvl_dev *ipvlan, struct in_addr *ip4_addr) |
918 | { | 924 | { |
@@ -993,6 +999,7 @@ static struct notifier_block ipvlan_notifier_block __read_mostly = { | |||
993 | .notifier_call = ipvlan_device_event, | 999 | .notifier_call = ipvlan_device_event, |
994 | }; | 1000 | }; |
995 | 1001 | ||
1002 | #if IS_ENABLED(CONFIG_IPV6) | ||
996 | static struct notifier_block ipvlan_addr6_notifier_block __read_mostly = { | 1003 | static struct notifier_block ipvlan_addr6_notifier_block __read_mostly = { |
997 | .notifier_call = ipvlan_addr6_event, | 1004 | .notifier_call = ipvlan_addr6_event, |
998 | }; | 1005 | }; |
@@ -1000,6 +1007,7 @@ static struct notifier_block ipvlan_addr6_notifier_block __read_mostly = { | |||
1000 | static struct notifier_block ipvlan_addr6_vtor_notifier_block __read_mostly = { | 1007 | static struct notifier_block ipvlan_addr6_vtor_notifier_block __read_mostly = { |
1001 | .notifier_call = ipvlan_addr6_validator_event, | 1008 | .notifier_call = ipvlan_addr6_validator_event, |
1002 | }; | 1009 | }; |
1010 | #endif | ||
1003 | 1011 | ||
1004 | static void ipvlan_ns_exit(struct net *net) | 1012 | static void ipvlan_ns_exit(struct net *net) |
1005 | { | 1013 | { |
@@ -1024,9 +1032,11 @@ static int __init ipvlan_init_module(void) | |||
1024 | 1032 | ||
1025 | ipvlan_init_secret(); | 1033 | ipvlan_init_secret(); |
1026 | register_netdevice_notifier(&ipvlan_notifier_block); | 1034 | register_netdevice_notifier(&ipvlan_notifier_block); |
1035 | #if IS_ENABLED(CONFIG_IPV6) | ||
1027 | register_inet6addr_notifier(&ipvlan_addr6_notifier_block); | 1036 | register_inet6addr_notifier(&ipvlan_addr6_notifier_block); |
1028 | register_inet6addr_validator_notifier( | 1037 | register_inet6addr_validator_notifier( |
1029 | &ipvlan_addr6_vtor_notifier_block); | 1038 | &ipvlan_addr6_vtor_notifier_block); |
1039 | #endif | ||
1030 | register_inetaddr_notifier(&ipvlan_addr4_notifier_block); | 1040 | register_inetaddr_notifier(&ipvlan_addr4_notifier_block); |
1031 | register_inetaddr_validator_notifier(&ipvlan_addr4_vtor_notifier_block); | 1041 | register_inetaddr_validator_notifier(&ipvlan_addr4_vtor_notifier_block); |
1032 | 1042 | ||
@@ -1045,9 +1055,11 @@ error: | |||
1045 | unregister_inetaddr_notifier(&ipvlan_addr4_notifier_block); | 1055 | unregister_inetaddr_notifier(&ipvlan_addr4_notifier_block); |
1046 | unregister_inetaddr_validator_notifier( | 1056 | unregister_inetaddr_validator_notifier( |
1047 | &ipvlan_addr4_vtor_notifier_block); | 1057 | &ipvlan_addr4_vtor_notifier_block); |
1058 | #if IS_ENABLED(CONFIG_IPV6) | ||
1048 | unregister_inet6addr_notifier(&ipvlan_addr6_notifier_block); | 1059 | unregister_inet6addr_notifier(&ipvlan_addr6_notifier_block); |
1049 | unregister_inet6addr_validator_notifier( | 1060 | unregister_inet6addr_validator_notifier( |
1050 | &ipvlan_addr6_vtor_notifier_block); | 1061 | &ipvlan_addr6_vtor_notifier_block); |
1062 | #endif | ||
1051 | unregister_netdevice_notifier(&ipvlan_notifier_block); | 1063 | unregister_netdevice_notifier(&ipvlan_notifier_block); |
1052 | return err; | 1064 | return err; |
1053 | } | 1065 | } |
@@ -1060,9 +1072,11 @@ static void __exit ipvlan_cleanup_module(void) | |||
1060 | unregister_inetaddr_notifier(&ipvlan_addr4_notifier_block); | 1072 | unregister_inetaddr_notifier(&ipvlan_addr4_notifier_block); |
1061 | unregister_inetaddr_validator_notifier( | 1073 | unregister_inetaddr_validator_notifier( |
1062 | &ipvlan_addr4_vtor_notifier_block); | 1074 | &ipvlan_addr4_vtor_notifier_block); |
1075 | #if IS_ENABLED(CONFIG_IPV6) | ||
1063 | unregister_inet6addr_notifier(&ipvlan_addr6_notifier_block); | 1076 | unregister_inet6addr_notifier(&ipvlan_addr6_notifier_block); |
1064 | unregister_inet6addr_validator_notifier( | 1077 | unregister_inet6addr_validator_notifier( |
1065 | &ipvlan_addr6_vtor_notifier_block); | 1078 | &ipvlan_addr6_vtor_notifier_block); |
1079 | #endif | ||
1066 | } | 1080 | } |
1067 | 1081 | ||
1068 | module_init(ipvlan_init_module); | 1082 | module_init(ipvlan_init_module); |