Changeset View
Changeset View
Standalone View
Standalone View
sbin/ifconfig/ifvlan.c
/* | /* | ||||
* Copyright (c) 1999 | * Copyright (c) 1999 Bill Paul <wpaul@ctr.columbia.edu> | ||||
* Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved. | * Copyright (c) 2012 ADARA Networks, Inc. | ||||
* All rights reserved. | |||||
* | * | ||||
* Portions of this software were developed by Robert N. M. Watson under | |||||
* contract to ADARA Networks, Inc. | |||||
* | |||||
* Redistribution and use in source and binary forms, with or without | * Redistribution and use in source and binary forms, with or without | ||||
* modification, are permitted provided that the following conditions | * modification, are permitted provided that the following conditions | ||||
* are met: | * are met: | ||||
* 1. Redistributions of source code must retain the above copyright | * 1. Redistributions of source code must retain the above copyright | ||||
* notice, this list of conditions and the following disclaimer. | * notice, this list of conditions and the following disclaimer. | ||||
* 2. Redistributions in binary form must reproduce the above copyright | * 2. Redistributions in binary form must reproduce the above copyright | ||||
* notice, this list of conditions and the following disclaimer in the | * notice, this list of conditions and the following disclaimer in the | ||||
* documentation and/or other materials provided with the distribution. | * documentation and/or other materials provided with the distribution. | ||||
▲ Show 20 Lines • Show All 60 Lines • ▼ Show 20 Lines | getvlan(int s, struct ifreq *ifr, struct vlanreq *vreq) | ||||
return ioctl(s, SIOCGETVLAN, (caddr_t)ifr); | return ioctl(s, SIOCGETVLAN, (caddr_t)ifr); | ||||
} | } | ||||
static void | static void | ||||
vlan_status(int s) | vlan_status(int s) | ||||
{ | { | ||||
struct vlanreq vreq; | struct vlanreq vreq; | ||||
if (getvlan(s, &ifr, &vreq) != -1) | if (getvlan(s, &ifr, &vreq) == -1) | ||||
printf("\tvlan: %d parent interface: %s\n", | return; | ||||
vreq.vlr_tag, vreq.vlr_parent[0] == '\0' ? | printf("\tvlan: %d", vreq.vlr_tag); | ||||
if (ioctl(s, SIOCGVLANPCP, (caddr_t)&ifr) != -1) | |||||
printf(" vlanpcp: %u", ifr.ifr_vlan_pcp); | |||||
printf(" parent interface: %s", vreq.vlr_parent[0] == '\0' ? | |||||
"<none>" : vreq.vlr_parent); | "<none>" : vreq.vlr_parent); | ||||
printf("\n"); | |||||
} | } | ||||
static void | static void | ||||
vlan_create(int s, struct ifreq *ifr) | vlan_create(int s, struct ifreq *ifr) | ||||
{ | { | ||||
if (params.vlr_tag != NOTAG || params.vlr_parent[0] != '\0') { | if (params.vlr_tag != NOTAG || params.vlr_parent[0] != '\0') { | ||||
/* | /* | ||||
* One or both parameters were specified, make sure both. | * One or both parameters were specified, make sure both. | ||||
▲ Show 20 Lines • Show All 51 Lines • ▼ Show 20 Lines | DECL_CMD_FUNC(setvlandev, val, d) | ||||
strlcpy(params.vlr_parent, val, sizeof(params.vlr_parent)); | strlcpy(params.vlr_parent, val, sizeof(params.vlr_parent)); | ||||
if (getvlan(s, &ifr, &vreq) != -1) | if (getvlan(s, &ifr, &vreq) != -1) | ||||
vlan_set(s, &ifr); | vlan_set(s, &ifr); | ||||
} | } | ||||
static | static | ||||
DECL_CMD_FUNC(setvlanpcp, val, d) | |||||
{ | |||||
u_long ul; | |||||
char *endp; | |||||
ul = strtoul(val, &endp, 0); | |||||
if (*endp != '\0') | |||||
errx(1, "invalid value for vlanpcp"); | |||||
if (ul > 7) | |||||
errx(1, "value for vlanpcp out of range"); | |||||
ifr.ifr_vlan_pcp = ul; | |||||
if (ioctl(s, SIOCSVLANPCP, (caddr_t)&ifr) == -1) | |||||
err(1, "SIOCSVLANPCP"); | |||||
} | |||||
static | |||||
DECL_CMD_FUNC(unsetvlandev, val, d) | DECL_CMD_FUNC(unsetvlandev, val, d) | ||||
{ | { | ||||
struct vlanreq vreq; | struct vlanreq vreq; | ||||
bzero((char *)&vreq, sizeof(struct vlanreq)); | bzero((char *)&vreq, sizeof(struct vlanreq)); | ||||
ifr.ifr_data = (caddr_t)&vreq; | ifr.ifr_data = (caddr_t)&vreq; | ||||
if (ioctl(s, SIOCGETVLAN, (caddr_t)&ifr) == -1) | if (ioctl(s, SIOCGETVLAN, (caddr_t)&ifr) == -1) | ||||
err(1, "SIOCGETVLAN"); | err(1, "SIOCGETVLAN"); | ||||
bzero((char *)&vreq.vlr_parent, sizeof(vreq.vlr_parent)); | bzero((char *)&vreq.vlr_parent, sizeof(vreq.vlr_parent)); | ||||
vreq.vlr_tag = 0; | vreq.vlr_tag = 0; | ||||
if (ioctl(s, SIOCSETVLAN, (caddr_t)&ifr) == -1) | if (ioctl(s, SIOCSETVLAN, (caddr_t)&ifr) == -1) | ||||
err(1, "SIOCSETVLAN"); | err(1, "SIOCSETVLAN"); | ||||
} | } | ||||
static struct cmd vlan_cmds[] = { | static struct cmd vlan_cmds[] = { | ||||
DEF_CLONE_CMD_ARG("vlan", setvlantag), | DEF_CLONE_CMD_ARG("vlan", setvlantag), | ||||
DEF_CLONE_CMD_ARG("vlandev", setvlandev), | DEF_CLONE_CMD_ARG("vlandev", setvlandev), | ||||
DEF_CMD_ARG("vlanpcp", setvlanpcp), | |||||
/* NB: non-clone cmds */ | /* NB: non-clone cmds */ | ||||
DEF_CMD_ARG("vlan", setvlantag), | DEF_CMD_ARG("vlan", setvlantag), | ||||
DEF_CMD_ARG("vlandev", setvlandev), | DEF_CMD_ARG("vlandev", setvlandev), | ||||
/* XXX For compatibility. Should become DEF_CMD() some day. */ | /* XXX For compatibility. Should become DEF_CMD() some day. */ | ||||
DEF_CMD_OPTARG("-vlandev", unsetvlandev), | DEF_CMD_OPTARG("-vlandev", unsetvlandev), | ||||
DEF_CMD("vlanmtu", IFCAP_VLAN_MTU, setifcap), | DEF_CMD("vlanmtu", IFCAP_VLAN_MTU, setifcap), | ||||
DEF_CMD("-vlanmtu", -IFCAP_VLAN_MTU, setifcap), | DEF_CMD("-vlanmtu", -IFCAP_VLAN_MTU, setifcap), | ||||
DEF_CMD("vlanhwtag", IFCAP_VLAN_HWTAGGING, setifcap), | DEF_CMD("vlanhwtag", IFCAP_VLAN_HWTAGGING, setifcap), | ||||
Show All 25 Lines |