Skip to content

Commit c1d3ee9

Browse files
kaberDavid S. Miller
authored andcommitted
[VLAN]: Split up device checks
Move the checks of the underlying device to a seperate function. Signed-off-by: Patrick McHardy <kaber@trash.net> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 42429aa commit c1d3ee9

File tree

1 file changed

+32
-24
lines changed

1 file changed

+32
-24
lines changed

net/8021q/vlan.c

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -410,57 +410,65 @@ static void vlan_transfer_operstate(const struct net_device *dev, struct net_dev
410410
}
411411
}
412412

413-
/* Attach a VLAN device to a mac address (ie Ethernet Card).
414-
* Returns the device that was created, or NULL if there was
415-
* an error of some kind.
416-
*/
417-
static struct net_device *register_vlan_device(struct net_device *real_dev,
418-
unsigned short VLAN_ID)
413+
static int vlan_check_real_dev(struct net_device *real_dev, unsigned short vlan_id)
419414
{
420-
struct vlan_group *grp, *ngrp = NULL;
421-
struct net_device *new_dev;
422-
char name[IFNAMSIZ];
423-
424-
#ifdef VLAN_DEBUG
425-
printk(VLAN_DBG "%s: if_name -:%s:- vid: %i\n",
426-
__FUNCTION__, eth_IF_name, VLAN_ID);
427-
#endif
428-
429-
if (VLAN_ID >= VLAN_VID_MASK)
430-
goto out_ret_null;
431-
432415
if (real_dev->features & NETIF_F_VLAN_CHALLENGED) {
433416
printk(VLAN_DBG "%s: VLANs not supported on %s.\n",
434417
__FUNCTION__, real_dev->name);
435-
goto out_ret_null;
418+
return -EOPNOTSUPP;
436419
}
437420

438421
if ((real_dev->features & NETIF_F_HW_VLAN_RX) &&
439422
!real_dev->vlan_rx_register) {
440423
printk(VLAN_DBG "%s: Device %s has buggy VLAN hw accel.\n",
441424
__FUNCTION__, real_dev->name);
442-
goto out_ret_null;
425+
return -EOPNOTSUPP;
443426
}
444427

445428
if ((real_dev->features & NETIF_F_HW_VLAN_FILTER) &&
446429
(!real_dev->vlan_rx_add_vid || !real_dev->vlan_rx_kill_vid)) {
447430
printk(VLAN_DBG "%s: Device %s has buggy VLAN hw accel.\n",
448431
__FUNCTION__, real_dev->name);
449-
goto out_ret_null;
432+
return -EOPNOTSUPP;
450433
}
451434

452435
/* The real device must be up and operating in order to
453436
* assosciate a VLAN device with it.
454437
*/
455438
if (!(real_dev->flags & IFF_UP))
456-
goto out_ret_null;
439+
return -ENETDOWN;
457440

458-
if (__find_vlan_dev(real_dev, VLAN_ID) != NULL) {
441+
if (__find_vlan_dev(real_dev, vlan_id) != NULL) {
459442
/* was already registered. */
460443
printk(VLAN_DBG "%s: ALREADY had VLAN registered\n", __FUNCTION__);
461-
goto out_ret_null;
444+
return -EEXIST;
462445
}
463446

447+
return 0;
448+
}
449+
450+
/* Attach a VLAN device to a mac address (ie Ethernet Card).
451+
* Returns the device that was created, or NULL if there was
452+
* an error of some kind.
453+
*/
454+
static struct net_device *register_vlan_device(struct net_device *real_dev,
455+
unsigned short VLAN_ID)
456+
{
457+
struct vlan_group *grp, *ngrp = NULL;
458+
struct net_device *new_dev;
459+
char name[IFNAMSIZ];
460+
461+
#ifdef VLAN_DEBUG
462+
printk(VLAN_DBG "%s: if_name -:%s:- vid: %i\n",
463+
__FUNCTION__, eth_IF_name, VLAN_ID);
464+
#endif
465+
466+
if (VLAN_ID >= VLAN_VID_MASK)
467+
goto out_ret_null;
468+
469+
if (vlan_check_real_dev(real_dev, VLAN_ID) < 0)
470+
goto out_ret_null;
471+
464472
/* Gotta set up the fields for the device. */
465473
#ifdef VLAN_DEBUG
466474
printk(VLAN_DBG "About to allocate name, vlan_name_type: %i\n",

0 commit comments

Comments
 (0)