Skip to content

Commit

Permalink
ipvlan: Add new func ipvlan_is_valid_dev instead of duplicated codes
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
gfreewind authored and davem330 committed Dec 3, 2017
1 parent 0653cb2 commit 5e51fe6
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions drivers/net/ipvlan/ipvlan_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -850,17 +850,27 @@ static void ipvlan_del_addr6(struct ipvl_dev *ipvlan, struct in6_addr *ip6_addr)
return ipvlan_del_addr(ipvlan, ip6_addr, true);
}

static bool ipvlan_is_valid_dev(const struct net_device *dev)
{
struct ipvl_dev *ipvlan = netdev_priv(dev);

if (!netif_is_ipvlan(dev))
return false;

if (!ipvlan || !ipvlan->port)
return false;

return true;
}

static int ipvlan_addr6_event(struct notifier_block *unused,
unsigned long event, void *ptr)
{
struct inet6_ifaddr *if6 = (struct inet6_ifaddr *)ptr;
struct net_device *dev = (struct net_device *)if6->idev->dev;
struct ipvl_dev *ipvlan = netdev_priv(dev);

if (!netif_is_ipvlan(dev))
return NOTIFY_DONE;

if (!ipvlan || !ipvlan->port)
if (!ipvlan_is_valid_dev(dev))
return NOTIFY_DONE;

switch (event) {
Expand Down Expand Up @@ -888,10 +898,7 @@ static int ipvlan_addr6_validator_event(struct notifier_block *unused,
if (in_softirq())
return NOTIFY_DONE;

if (!netif_is_ipvlan(dev))
return NOTIFY_DONE;

if (!ipvlan || !ipvlan->port)
if (!ipvlan_is_valid_dev(dev))
return NOTIFY_DONE;

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

if (!netif_is_ipvlan(dev))
return NOTIFY_DONE;

if (!ipvlan || !ipvlan->port)
if (!ipvlan_is_valid_dev(dev))
return NOTIFY_DONE;

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

if (!netif_is_ipvlan(dev))
return NOTIFY_DONE;

if (!ipvlan || !ipvlan->port)
if (!ipvlan_is_valid_dev(dev))
return NOTIFY_DONE;

switch (event) {
Expand Down

0 comments on commit 5e51fe6

Please sign in to comment.