diff options
| author | Gao Feng <gfree.wind@vip.163.com> | 2017-12-01 03:33:03 -0500 |
|---|---|---|
| committer | David S. Miller <davem@davemloft.net> | 2017-12-03 09:46:42 -0500 |
| commit | 5e51fe6f4472510a85e637907e24d4fbe5e39489 (patch) | |
| tree | 9029011a1792dc76e1b35cd95396706082d5517c /drivers/net/ipvlan/ipvlan_main.c | |
| parent | 0653cb2e1d1d8c1e965533ce3f167251d5e7cdd1 (diff) | |
ipvlan: Add new func ipvlan_is_valid_dev instead of duplicated codes
There are multiple duplicated condition checks in the current codes, so
I add the new func ipvlan_is_valid_dev instead of the duplicated codes to
check if the netdev is real ipvlan dev.
Signed-off-by: Gao Feng <gfree.wind@vip.163.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 | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/drivers/net/ipvlan/ipvlan_main.c b/drivers/net/ipvlan/ipvlan_main.c index 30cb803e2fe5..2469df118fbf 100644 --- a/drivers/net/ipvlan/ipvlan_main.c +++ b/drivers/net/ipvlan/ipvlan_main.c | |||
| @@ -850,6 +850,19 @@ static void ipvlan_del_addr6(struct ipvl_dev *ipvlan, struct in6_addr *ip6_addr) | |||
| 850 | return ipvlan_del_addr(ipvlan, ip6_addr, true); | 850 | return ipvlan_del_addr(ipvlan, ip6_addr, true); |
| 851 | } | 851 | } |
| 852 | 852 | ||
| 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 | |||
| 853 | static int ipvlan_addr6_event(struct notifier_block *unused, | 866 | static int ipvlan_addr6_event(struct notifier_block *unused, |
| 854 | unsigned long event, void *ptr) | 867 | unsigned long event, void *ptr) |
| 855 | { | 868 | { |
| @@ -857,10 +870,7 @@ static int ipvlan_addr6_event(struct notifier_block *unused, | |||
| 857 | struct net_device *dev = (struct net_device *)if6->idev->dev; | 870 | struct net_device *dev = (struct net_device *)if6->idev->dev; |
| 858 | struct ipvl_dev *ipvlan = netdev_priv(dev); | 871 | struct ipvl_dev *ipvlan = netdev_priv(dev); |
| 859 | 872 | ||
| 860 | if (!netif_is_ipvlan(dev)) | 873 | if (!ipvlan_is_valid_dev(dev)) |
| 861 | return NOTIFY_DONE; | ||
| 862 | |||
| 863 | if (!ipvlan || !ipvlan->port) | ||
| 864 | return NOTIFY_DONE; | 874 | return NOTIFY_DONE; |
| 865 | 875 | ||
| 866 | switch (event) { | 876 | switch (event) { |
| @@ -888,10 +898,7 @@ static int ipvlan_addr6_validator_event(struct notifier_block *unused, | |||
| 888 | if (in_softirq()) | 898 | if (in_softirq()) |
| 889 | return NOTIFY_DONE; | 899 | return NOTIFY_DONE; |
| 890 | 900 | ||
| 891 | if (!netif_is_ipvlan(dev)) | 901 | if (!ipvlan_is_valid_dev(dev)) |
| 892 | return NOTIFY_DONE; | ||
| 893 | |||
| 894 | if (!ipvlan || !ipvlan->port) | ||
| 895 | return NOTIFY_DONE; | 902 | return NOTIFY_DONE; |
| 896 | 903 | ||
| 897 | switch (event) { | 904 | switch (event) { |
| @@ -932,10 +939,7 @@ static int ipvlan_addr4_event(struct notifier_block *unused, | |||
| 932 | struct ipvl_dev *ipvlan = netdev_priv(dev); | 939 | struct ipvl_dev *ipvlan = netdev_priv(dev); |
| 933 | struct in_addr ip4_addr; | 940 | struct in_addr ip4_addr; |
| 934 | 941 | ||
| 935 | if (!netif_is_ipvlan(dev)) | 942 | if (!ipvlan_is_valid_dev(dev)) |
| 936 | return NOTIFY_DONE; | ||
| 937 | |||
| 938 | if (!ipvlan || !ipvlan->port) | ||
| 939 | return NOTIFY_DONE; | 943 | return NOTIFY_DONE; |
| 940 | 944 | ||
| 941 | switch (event) { | 945 | switch (event) { |
| @@ -961,10 +965,7 @@ static int ipvlan_addr4_validator_event(struct notifier_block *unused, | |||
| 961 | struct net_device *dev = (struct net_device *)ivi->ivi_dev->dev; | 965 | struct net_device *dev = (struct net_device *)ivi->ivi_dev->dev; |
| 962 | struct ipvl_dev *ipvlan = netdev_priv(dev); | 966 | struct ipvl_dev *ipvlan = netdev_priv(dev); |
| 963 | 967 | ||
| 964 | if (!netif_is_ipvlan(dev)) | 968 | if (!ipvlan_is_valid_dev(dev)) |
| 965 | return NOTIFY_DONE; | ||
| 966 | |||
| 967 | if (!ipvlan || !ipvlan->port) | ||
| 968 | return NOTIFY_DONE; | 969 | return NOTIFY_DONE; |
| 969 | 970 | ||
| 970 | switch (event) { | 971 | switch (event) { |
