]> git.saurik.com Git - apple/network_cmds.git/blob - ifconfig.tproj/ifvlan.c
1a547df3a8f9d341de80b1c7c7bc2f9d4a39fd36
[apple/network_cmds.git] / ifconfig.tproj / ifvlan.c
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
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by Bill Paul.
16 * 4. Neither the name of the author nor the names of any co-contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
30 * THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33 #include <sys/param.h>
34 #define KERNEL_PRIVATE
35 #include <sys/ioctl.h>
36 #undef KERNEL_PRIVATE
37 #include <sys/socket.h>
38 #include <sys/sockio.h>
39
40 #include <stdlib.h>
41 #include <unistd.h>
42
43 #include <net/ethernet.h>
44 #include <net/if.h>
45 #include <net/if_var.h>
46 #include <net/if_vlan_var.h>
47 #include <net/route.h>
48
49 #include <ctype.h>
50 #include <stdio.h>
51 #include <string.h>
52 #include <stdlib.h>
53 #include <unistd.h>
54 #include <err.h>
55 #include <errno.h>
56
57 #include "ifconfig.h"
58
59 static int __tag = 0;
60 static int __have_tag = 0;
61
62 void
63 vlan_status(int s, struct rt_addrinfo *info __unused)
64 {
65 struct vlanreq vreq;
66
67 bzero((char *)&vreq, sizeof(struct vlanreq));
68 ifr.ifr_data = (caddr_t)&vreq;
69
70 if (ioctl(s, SIOCGETVLAN, (caddr_t)&ifr) == -1)
71 return;
72
73 printf("\tvlan: %d parent interface: %s\n",
74 vreq.vlr_tag, vreq.vlr_parent[0] == '\0' ?
75 "<none>" : vreq.vlr_parent);
76
77 return;
78 }
79
80 void
81 setvlantag(const char *val, int d, int s, const struct afswtch *afp)
82 {
83 u_int16_t tag;
84 struct vlanreq vreq;
85
86 __tag = tag = atoi(val);
87 __have_tag = 1;
88
89 bzero((char *)&vreq, sizeof(struct vlanreq));
90 ifr.ifr_data = (caddr_t)&vreq;
91
92 if (ioctl(s, SIOCGETVLAN, (caddr_t)&ifr) == -1)
93 err(1, "SIOCGETVLAN");
94
95 vreq.vlr_tag = tag;
96
97 if (ioctl(s, SIOCSETVLAN, (caddr_t)&ifr) == -1)
98 err(1, "SIOCSETVLAN");
99
100 return;
101 }
102
103 void
104 setvlandev(const char *val, int d, int s, const struct afswtch *afp)
105 {
106 struct vlanreq vreq;
107
108 if (!__have_tag)
109 errx(1, "must specify both vlan tag and device");
110
111 bzero((char *)&vreq, sizeof(struct vlanreq));
112 ifr.ifr_data = (caddr_t)&vreq;
113
114 if (ioctl(s, SIOCGETVLAN, (caddr_t)&ifr) == -1)
115 err(1, "SIOCGETVLAN");
116
117 strncpy(vreq.vlr_parent, val, sizeof(vreq.vlr_parent));
118 vreq.vlr_tag = __tag;
119
120 if (ioctl(s, SIOCSETVLAN, (caddr_t)&ifr) == -1)
121 err(1, "SIOCSETVLAN");
122
123 return;
124 }
125
126 void
127 unsetvlandev(const char *val, int d, int s, const struct afswtch *afp)
128 {
129 struct vlanreq vreq;
130
131 bzero((char *)&vreq, sizeof(struct vlanreq));
132 ifr.ifr_data = (caddr_t)&vreq;
133
134 if (ioctl(s, SIOCGETVLAN, (caddr_t)&ifr) == -1)
135 err(1, "SIOCGETVLAN");
136
137 bzero((char *)&vreq.vlr_parent, sizeof(vreq.vlr_parent));
138 vreq.vlr_tag = 0;
139
140 if (ioctl(s, SIOCSETVLAN, (caddr_t)&ifr) == -1)
141 err(1, "SIOCSETVLAN");
142
143 return;
144 }