Skip to content

Commit 5e51fe6

Browse files
gfreewinddavem330
authored andcommitted
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 <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 0653cb2 commit 5e51fe6

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

drivers/net/ipvlan/ipvlan_main.c

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -850,17 +850,27 @@ static void ipvlan_del_addr6(struct ipvl_dev *ipvlan, struct in6_addr *ip6_addr)
850850
return ipvlan_del_addr(ipvlan, ip6_addr, true);
851851
}
852852

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+
853866
static int ipvlan_addr6_event(struct notifier_block *unused,
854867
unsigned long event, void *ptr)
855868
{
856869
struct inet6_ifaddr *if6 = (struct inet6_ifaddr *)ptr;
857870
struct net_device *dev = (struct net_device *)if6->idev->dev;
858871
struct ipvl_dev *ipvlan = netdev_priv(dev);
859872

860-
if (!netif_is_ipvlan(dev))
861-
return NOTIFY_DONE;
862-
863-
if (!ipvlan || !ipvlan->port)
873+
if (!ipvlan_is_valid_dev(dev))
864874
return NOTIFY_DONE;
865875

866876
switch (event) {
@@ -888,10 +898,7 @@ static int ipvlan_addr6_validator_event(struct notifier_block *unused,
888898
if (in_softirq())
889899
return NOTIFY_DONE;
890900

891-
if (!netif_is_ipvlan(dev))
892-
return NOTIFY_DONE;
893-
894-
if (!ipvlan || !ipvlan->port)
901+
if (!ipvlan_is_valid_dev(dev))
895902
return NOTIFY_DONE;
896903

897904
switch (event) {
@@ -932,10 +939,7 @@ static int ipvlan_addr4_event(struct notifier_block *unused,
932939
struct ipvl_dev *ipvlan = netdev_priv(dev);
933940
struct in_addr ip4_addr;
934941

935-
if (!netif_is_ipvlan(dev))
936-
return NOTIFY_DONE;
937-
938-
if (!ipvlan || !ipvlan->port)
942+
if (!ipvlan_is_valid_dev(dev))
939943
return NOTIFY_DONE;
940944

941945
switch (event) {
@@ -961,10 +965,7 @@ static int ipvlan_addr4_validator_event(struct notifier_block *unused,
961965
struct net_device *dev = (struct net_device *)ivi->ivi_dev->dev;
962966
struct ipvl_dev *ipvlan = netdev_priv(dev);
963967

964-
if (!netif_is_ipvlan(dev))
965-
return NOTIFY_DONE;
966-
967-
if (!ipvlan || !ipvlan->port)
968+
if (!ipvlan_is_valid_dev(dev))
968969
return NOTIFY_DONE;
969970

970971
switch (event) {

0 commit comments

Comments
 (0)