Deleted Added
full compact
ifvlan.c (150736) ifvlan.c (150907)
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 150736 2005-09-29 23:38:24Z yar $";
59 "$FreeBSD: head/sbin/ifconfig/ifvlan.c 150907 2005-10-04 11:48:03Z yar $";
60#endif
60#endif
61static int __tag = 0;
61static struct vlanreq __vreq;
62static int __have_dev = 0;
62static int __have_tag = 0;
63
64static void
65vlan_status(int s)
66{
67 struct vlanreq vreq;
68
69 bzero((char *)&vreq, sizeof(struct vlanreq));

--- 7 unchanged lines hidden (view full) ---

77 "<none>" : vreq.vlr_parent);
78
79 return;
80}
81
82static void
83setvlantag(const char *val, int d, int s, const struct afswtch *afp)
84{
63static int __have_tag = 0;
64
65static void
66vlan_status(int s)
67{
68 struct vlanreq vreq;
69
70 bzero((char *)&vreq, sizeof(struct vlanreq));

--- 7 unchanged lines hidden (view full) ---

78 "<none>" : vreq.vlr_parent);
79
80 return;
81}
82
83static void
84setvlantag(const char *val, int d, int s, const struct afswtch *afp)
85{
85 u_int16_t tag;
86 struct vlanreq vreq;
86 char *endp;
87 u_long ul;
87
88
88 __tag = tag = atoi(val);
89 ul = strtoul(val, &endp, 0);
90 if (*endp != '\0')
91 errx(1, "invalid value for vlan");
92 __vreq.vlr_tag = ul;
93 /* check if the value can be represented in vlr_tag */
94 if (__vreq.vlr_tag != ul)
95 errx(1, "value for vlan out of range");
96 /* the kernel will do more specific checks on vlr_tag */
89 __have_tag = 1;
97 __have_tag = 1;
90
91 bzero((char *)&vreq, sizeof(struct vlanreq));
92 ifr.ifr_data = (caddr_t)&vreq;
93
94 if (ioctl(s, SIOCGETVLAN, (caddr_t)&ifr) == -1)
95 err(1, "SIOCGETVLAN");
96
97 vreq.vlr_tag = tag;
98
99 if (ioctl(s, SIOCSETVLAN, (caddr_t)&ifr) == -1)
100 err(1, "SIOCSETVLAN");
101
102 return;
103}
104
105static void
106setvlandev(const char *val, int d, int s, const struct afswtch *afp)
107{
98}
99
100static void
101setvlandev(const char *val, int d, int s, const struct afswtch *afp)
102{
108 struct vlanreq vreq;
109
103
110 if (!__have_tag)
111 errx(1, "must specify both vlan tag and device");
112
113 bzero((char *)&vreq, sizeof(struct vlanreq));
114 ifr.ifr_data = (caddr_t)&vreq;
115
116 if (ioctl(s, SIOCGETVLAN, (caddr_t)&ifr) == -1)
117 err(1, "SIOCGETVLAN");
118
119 strncpy(vreq.vlr_parent, val, sizeof(vreq.vlr_parent));
120 vreq.vlr_tag = __tag;
121
122 if (ioctl(s, SIOCSETVLAN, (caddr_t)&ifr) == -1)
123 err(1, "SIOCSETVLAN");
124
125 return;
104 strncpy(__vreq.vlr_parent, val, sizeof(__vreq.vlr_parent));
105 __have_dev = 1;
126}
127
128static void
129unsetvlandev(const char *val, int d, int s, const struct afswtch *afp)
130{
131 struct vlanreq vreq;
132
133 if (val != NULL)
134 warnx("argument to -vlandev is useless and hence deprecated");
135
136 bzero((char *)&vreq, sizeof(struct vlanreq));
137 ifr.ifr_data = (caddr_t)&vreq;
138
139 if (ioctl(s, SIOCGETVLAN, (caddr_t)&ifr) == -1)
140 err(1, "SIOCGETVLAN");
141
142 bzero((char *)&vreq.vlr_parent, sizeof(vreq.vlr_parent));
106}
107
108static void
109unsetvlandev(const char *val, int d, int s, const struct afswtch *afp)
110{
111 struct vlanreq vreq;
112
113 if (val != NULL)
114 warnx("argument to -vlandev is useless and hence deprecated");
115
116 bzero((char *)&vreq, sizeof(struct vlanreq));
117 ifr.ifr_data = (caddr_t)&vreq;
118
119 if (ioctl(s, SIOCGETVLAN, (caddr_t)&ifr) == -1)
120 err(1, "SIOCGETVLAN");
121
122 bzero((char *)&vreq.vlr_parent, sizeof(vreq.vlr_parent));
143 vreq.vlr_tag = 0;
123 vreq.vlr_tag = 0; /* XXX clear parent only (no kernel support now) */
144
145 if (ioctl(s, SIOCSETVLAN, (caddr_t)&ifr) == -1)
146 err(1, "SIOCSETVLAN");
124
125 if (ioctl(s, SIOCSETVLAN, (caddr_t)&ifr) == -1)
126 err(1, "SIOCSETVLAN");
127 __have_dev = __have_tag = 0;
128}
147
129
148 return;
130static void
131vlan_cb(int s, void *arg)
132{
133
134 if (__have_tag ^ __have_dev)
135 errx(1, "both vlan and vlandev must be specified");
136
137 if (__have_tag && __have_dev) {
138 ifr.ifr_data = (caddr_t)&__vreq;
139 if (ioctl(s, SIOCSETVLAN, (caddr_t)&ifr) == -1)
140 err(1, "SIOCSETVLAN");
141 }
149}
150
151static struct cmd vlan_cmds[] = {
152 DEF_CMD_ARG("vlan", setvlantag),
153 DEF_CMD_ARG("vlandev", setvlandev),
154 /* XXX For compatibility. Should become DEF_CMD() some day. */
155 DEF_CMD_OPTARG("-vlandev", unsetvlandev),
156 DEF_CMD("vlanmtu", IFCAP_VLAN_MTU, setifcap),

--- 11 unchanged lines hidden (view full) ---

168vlan_ctor(void)
169{
170#define N(a) (sizeof(a) / sizeof(a[0]))
171 int i;
172
173 for (i = 0; i < N(vlan_cmds); i++)
174 cmd_register(&vlan_cmds[i]);
175 af_register(&af_vlan);
142}
143
144static struct cmd vlan_cmds[] = {
145 DEF_CMD_ARG("vlan", setvlantag),
146 DEF_CMD_ARG("vlandev", setvlandev),
147 /* XXX For compatibility. Should become DEF_CMD() some day. */
148 DEF_CMD_OPTARG("-vlandev", unsetvlandev),
149 DEF_CMD("vlanmtu", IFCAP_VLAN_MTU, setifcap),

--- 11 unchanged lines hidden (view full) ---

161vlan_ctor(void)
162{
163#define N(a) (sizeof(a) / sizeof(a[0]))
164 int i;
165
166 for (i = 0; i < N(vlan_cmds); i++)
167 cmd_register(&vlan_cmds[i]);
168 af_register(&af_vlan);
169 callback_register(vlan_cb, NULL);
176#undef N
177}
170#undef N
171}