ifvlan.c (186101) | ifvlan.c (186108) |
---|---|
1/* 2 * Copyright (c) 1999 3 * Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 42 unchanged lines hidden (view full) --- 51#include <unistd.h> 52#include <err.h> 53#include <errno.h> 54 55#include "ifconfig.h" 56 57#ifndef lint 58static const char rcsid[] = | 1/* 2 * Copyright (c) 1999 3 * Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 42 unchanged lines hidden (view full) --- 51#include <unistd.h> 52#include <err.h> 53#include <errno.h> 54 55#include "ifconfig.h" 56 57#ifndef lint 58static const char rcsid[] = |
59 "$FreeBSD: head/sbin/ifconfig/ifvlan.c 186101 2008-12-15 01:06:49Z sam $"; | 59 "$FreeBSD: head/sbin/ifconfig/ifvlan.c 186108 2008-12-15 01:44:23Z sam $"; |
60#endif 61 62#define NOTAG ((u_short) -1) 63 64static struct vlanreq params = { 65 .vlr_tag = NOTAG, 66}; 67 --- 46 unchanged lines hidden (view full) --- 114{ 115 if (params.vlr_tag != NOTAG && params.vlr_parent[0] != '\0') { 116 ifr->ifr_data = (caddr_t) ¶ms; 117 if (ioctl(s, SIOCSETVLAN, (caddr_t)ifr) == -1) 118 err(1, "SIOCSETVLAN"); 119 } 120} 121 | 60#endif 61 62#define NOTAG ((u_short) -1) 63 64static struct vlanreq params = { 65 .vlr_tag = NOTAG, 66}; 67 --- 46 unchanged lines hidden (view full) --- 114{ 115 if (params.vlr_tag != NOTAG && params.vlr_parent[0] != '\0') { 116 ifr->ifr_data = (caddr_t) ¶ms; 117 if (ioctl(s, SIOCSETVLAN, (caddr_t)ifr) == -1) 118 err(1, "SIOCSETVLAN"); 119 } 120} 121 |
122static void 123getvlantag(const char *val) | 122static 123DECL_CMD_FUNC(setvlantag, val, d) |
124{ | 124{ |
125 struct vlanreq vreq; |
|
125 u_long ul; 126 char *endp; 127 128 ul = strtoul(val, &endp, 0); 129 if (*endp != '\0') 130 errx(1, "invalid value for vlan"); 131 params.vlr_tag = ul; 132 /* check if the value can be represented in vlr_tag */ 133 if (params.vlr_tag != ul) 134 errx(1, "value for vlan out of range"); | 126 u_long ul; 127 char *endp; 128 129 ul = strtoul(val, &endp, 0); 130 if (*endp != '\0') 131 errx(1, "invalid value for vlan"); 132 params.vlr_tag = ul; 133 /* check if the value can be represented in vlr_tag */ 134 if (params.vlr_tag != ul) 135 errx(1, "value for vlan out of range"); |
135} | |
136 | 136 |
137static 138DECL_CMD_FUNC(setvlantag_clone, val, d) 139{ 140 getvlantag(val); 141 clone_setcallback(vlan_create); | 137 if (getvlan(s, &ifr, &vreq) != -1) 138 vlan_set(s, &ifr); 139 else 140 clone_setcallback(vlan_create); |
142} 143 144static | 141} 142 143static |
145DECL_CMD_FUNC(setvlantag, val, d) 146{ 147 struct vlanreq vreq; 148 149 getvlantag(val); 150 if (getvlan(s, &ifr, &vreq) == -1) 151 errx(1, "no existing vlan"); 152 vlan_set(s, &ifr); 153} 154 155static 156DECL_CMD_FUNC(setvlandev_clone, val, d) 157{ 158 strlcpy(params.vlr_parent, val, sizeof(params.vlr_parent)); 159 clone_setcallback(vlan_create); 160} 161 162static | |
163DECL_CMD_FUNC(setvlandev, val, d) 164{ 165 struct vlanreq vreq; 166 167 strlcpy(params.vlr_parent, val, sizeof(params.vlr_parent)); | 144DECL_CMD_FUNC(setvlandev, val, d) 145{ 146 struct vlanreq vreq; 147 148 strlcpy(params.vlr_parent, val, sizeof(params.vlr_parent)); |
149 |
|
168 if (getvlan(s, &ifr, &vreq) != -1) | 150 if (getvlan(s, &ifr, &vreq) != -1) |
169 errx(1, "no existing vlan"); 170 vlan_set(s, &ifr); | 151 vlan_set(s, &ifr); 152 else 153 clone_setcallback(vlan_create); |
171} 172 173static 174DECL_CMD_FUNC(unsetvlandev, val, d) 175{ 176 struct vlanreq vreq; 177 178 bzero((char *)&vreq, sizeof(struct vlanreq)); --- 5 unchanged lines hidden (view full) --- 184 bzero((char *)&vreq.vlr_parent, sizeof(vreq.vlr_parent)); 185 vreq.vlr_tag = 0; 186 187 if (ioctl(s, SIOCSETVLAN, (caddr_t)&ifr) == -1) 188 err(1, "SIOCSETVLAN"); 189} 190 191static struct cmd vlan_cmds[] = { | 154} 155 156static 157DECL_CMD_FUNC(unsetvlandev, val, d) 158{ 159 struct vlanreq vreq; 160 161 bzero((char *)&vreq, sizeof(struct vlanreq)); --- 5 unchanged lines hidden (view full) --- 167 bzero((char *)&vreq.vlr_parent, sizeof(vreq.vlr_parent)); 168 vreq.vlr_tag = 0; 169 170 if (ioctl(s, SIOCSETVLAN, (caddr_t)&ifr) == -1) 171 err(1, "SIOCSETVLAN"); 172} 173 174static struct cmd vlan_cmds[] = { |
192 DEF_CLONE_CMD_ARG("vlan", setvlantag_clone), 193 DEF_CLONE_CMD_ARG("vlandev", setvlandev_clone), | 175 DEF_CLONE_CMD_ARG("vlan", setvlantag), 176 DEF_CLONE_CMD_ARG("vlandev", setvlandev), |
194 /* NB: non-clone cmds */ 195 DEF_CMD_ARG("vlan", setvlantag), 196 DEF_CMD_ARG("vlandev", setvlandev), 197 /* XXX For compatibility. Should become DEF_CMD() some day. */ 198 DEF_CMD_OPTARG("-vlandev", unsetvlandev), 199 DEF_CMD("vlanmtu", IFCAP_VLAN_MTU, setifcap), 200 DEF_CMD("-vlanmtu", -IFCAP_VLAN_MTU, setifcap), 201 DEF_CMD("vlanhwtag", IFCAP_VLAN_HWTAGGING, setifcap), --- 22 unchanged lines hidden --- | 177 /* NB: non-clone cmds */ 178 DEF_CMD_ARG("vlan", setvlantag), 179 DEF_CMD_ARG("vlandev", setvlandev), 180 /* XXX For compatibility. Should become DEF_CMD() some day. */ 181 DEF_CMD_OPTARG("-vlandev", unsetvlandev), 182 DEF_CMD("vlanmtu", IFCAP_VLAN_MTU, setifcap), 183 DEF_CMD("-vlanmtu", -IFCAP_VLAN_MTU, setifcap), 184 DEF_CMD("vlanhwtag", IFCAP_VLAN_HWTAGGING, setifcap), --- 22 unchanged lines hidden --- |