3 * ===================================
4 * HARP | Host ATM Research Platform
5 * ===================================
8 * This Host ATM Research Platform ("HARP") file (the "Software") is
9 * made available by Network Computing Services, Inc. ("NetworkCS")
10 * "AS IS". NetworkCS does not provide maintenance, improvements or
11 * support of any kind.
13 * NETWORKCS MAKES NO WARRANTIES OR REPRESENTATIONS, EXPRESS OR IMPLIED,
14 * INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY
15 * AND FITNESS FOR A PARTICULAR PURPOSE, AS TO ANY ELEMENT OF THE
16 * SOFTWARE OR ANY SUPPORT PROVIDED IN CONNECTION WITH THIS SOFTWARE.
17 * In no event shall NetworkCS be responsible for any damages, including
18 * but not limited to consequential damages, arising from or relating to
19 * any use of the Software or related support.
21 * Copyright 1994-1998 Network Computing Services, Inc.
23 * Copies of this Software may be made, however, the above copyright
24 * notice must be reproduced on all copies.
28 * User configuration and display program
29 * --------------------------------------
31 * Routines for "set" subcommand
35 #include <sys/param.h>
36 #include <sys/socket.h>
37 #include <sys/sockio.h>
39 #include <netinet/in.h>
40 #include <netatm/port.h>
41 #include <netatm/atm.h>
42 #include <netatm/atm_if.h>
43 #include <netatm/atm_sap.h>
44 #include <netatm/atm_sys.h>
45 #include <netatm/atm_ioctl.h>
57 __RCSID("@(#) $FreeBSD$");
62 * Process ATM ARP server set command
65 * atm set arpserver <interface_name> <atm-address> <IP prefix> ...
68 * argc number of arguments to command
69 * argv pointer to argument strings
70 * cmdp pointer to command description
77 set_arpserver(int argc, char **argv, const struct cmd *cmdp __unused)
82 size_t prefix_len = 0;
85 struct sockaddr_in *lis;
86 struct sockaddr_in if_mask;
89 struct air_netif_rsp *int_info;
91 struct in_addr ip_addr;
92 struct in_addr ip_mask;
96 * Validate interface name
98 check_netif_name(argv[0]);
103 * Get the ARP server's ATM address
105 bzero(&server, sizeof(server));
106 if (strcasecmp(argv[0], "local")) {
108 * ARP server NSAP address is provided
110 server.address_format = T_ATM_ENDSYS_ADDR;
111 server.address_length = sizeof(Atm_addr_nsap);
112 if (get_hex_atm_addr(argv[0],
113 (u_char *)server.address,
114 sizeof(Atm_addr_nsap)) !=
115 sizeof(Atm_addr_nsap)) {
116 fprintf(stderr, "%s: Invalid ARP server address\n",
121 fprintf(stderr, "%s: Invalid number of arguments\n",
130 * This host is the ARP server
132 server.address_format = T_ATM_ABSENT;
133 server.address_length = 0;
136 * Get interface information from the kernel. We need
137 * to get the IP address and the subnet mask associated
138 * with the network interface and insert them into the
139 * list of permitted LIS prefixes.
141 bzero(&air, sizeof(air));
142 air.air_opcode = AIOCS_INF_NIF;
143 strcpy(air.air_int_intf, intf);
144 len = do_info_ioctl(&air, sizeof(struct air_netif_rsp));
146 fprintf(stderr, "%s: ", prog);
150 perror("Internal error");
153 fprintf(stderr, "%s is not an ATM device\n",
157 perror("ioctl (AIOCINFO)");
162 int_info = (struct air_netif_rsp *) air.air_buf_addr;
163 lis = (struct sockaddr_in *)(void *)&int_info->anp_proto_addr;
164 prefix_buf[0].ip_addr = lis->sin_addr;
167 rc = get_subnet_mask(intf, &if_mask);
169 fprintf(stderr, "%s: Can't get subnet mask for %s\n",
172 prefix_buf[0].ip_mask = if_mask.sin_addr;
173 prefix_buf[0].ip_addr.s_addr &=
174 prefix_buf[0].ip_mask.s_addr;
177 * Get the prefixes of the LISs that we'll support
179 for (i = 1; argc; i++, argc--, argv++) {
180 rc = parse_ip_prefix(argv[0],
181 (struct in_addr *)&prefix_buf[i]);
183 fprintf(stderr, "%s: Invalid IP prefix value \'%s\'\n",
190 * Compress the prefix list
192 prefix_len = compress_prefix_list((struct in_addr *)prefix_buf,
193 i * sizeof(struct in_addr) * 2);
197 * Build ioctl request
199 bzero(&asr, sizeof(asr));
200 asr.asr_opcode = AIOCS_SET_ASV;
201 strncpy(asr.asr_arp_intf, intf, sizeof(asr.asr_arp_intf));
202 asr.asr_arp_addr = server;
203 asr.asr_arp_subaddr.address_format = T_ATM_ABSENT;
204 asr.asr_arp_subaddr.address_length = 0;
206 asr.asr_arp_pbuf = (caddr_t)prefix_buf;
208 asr.asr_arp_pbuf = (caddr_t)0;
209 asr.asr_arp_plen = prefix_len;
212 * Pass the new ARP server address to the kernel
214 s = socket(AF_ATM, SOCK_DGRAM, 0);
218 if (ioctl(s, AIOCSET, (caddr_t)&asr) < 0) {
219 fprintf(stderr, "%s: ", prog);
222 case EPROTONOSUPPORT:
223 perror("Internal error");
226 fprintf(stderr, "Invalid parameter\n");
229 fprintf(stderr, "Kernel memory exhausted\n");
232 fprintf(stderr, "ATM network is inoperable\n");
235 fprintf(stderr, "Must be super user to use set subcommand\n");
238 fprintf(stderr, "%s is not an ATM interface\n", intf);
241 fprintf(stderr, "Signalling manager not attached\n");
245 "%s does not have an IP address configured\n",
249 perror("Ioctl (AIOCSET) ARPSERVER address");
260 * Process set MAC address command
263 * atm set mac <interface_name> <MAC address>
266 * argc number of remaining arguments to command
267 * argv pointer to remaining argument strings
268 * cmdp pointer to command description
275 set_macaddr(int argc, char **argv, const struct cmd *cmdp __unused)
280 struct atmsetreq asr;
283 * Validate interface name
285 if (strlen(argv[0]) > sizeof(asr.asr_mac_intf) - 1) {
286 fprintf(stderr, "%s: Illegal interface name\n", prog);
293 * Get the MAC address provided by the user
295 if (get_hex_atm_addr(argv[0], (u_char *)&mac, sizeof(mac)) !=
297 fprintf(stderr, "%s: Invalid MAC address\n", prog);
302 * Build ioctl request
304 asr.asr_opcode = AIOCS_SET_MAC;
305 strncpy(asr.asr_mac_intf, intf, sizeof(asr.asr_mac_intf));
306 bcopy(&mac, &asr.asr_mac_addr, sizeof(asr.asr_mac_addr));
309 * Pass the new address to the kernel
311 s = socket(AF_ATM, SOCK_DGRAM, 0);
315 if (ioctl(s, AIOCSET, (caddr_t)&asr) < 0) {
316 fprintf(stderr, "%s: ", prog);
319 case EPROTONOSUPPORT:
320 perror("Internal error");
323 fprintf(stderr, "Interface must be detached to set MAC addres\n");
326 fprintf(stderr, "Invalid parameter\n");
329 fprintf(stderr, "Kernel memory exhausted\n");
332 fprintf(stderr, "ATM network is inoperable\n");
335 fprintf(stderr, "Must be super user to use set subcommand\n");
338 fprintf(stderr, "%s is not an ATM device\n",
342 perror("Ioctl (AIOCSET) MAC address");
353 * Process network interface set command
356 * atm set netif <interface_name> <prefix_name> <count>
359 * argc number of arguments to command
360 * argv pointer to argument strings
361 * cmdp pointer to command description
368 set_netif(int argc, char **argv, const struct cmd *cmdp __unused)
370 struct atmsetreq anr;
379 anr.asr_opcode = AIOCS_SET_NIF;
382 * Validate interface name
384 if (strlen(argv[0]) > sizeof(anr.asr_nif_intf) - 1) {
385 fprintf(stderr, "%s: Illegal interface name\n", prog);
388 strcpy(anr.asr_nif_intf, argv[0]);
392 * Validate network interface name prefix
394 if ((strlen(argv[0]) > sizeof(anr.asr_nif_pref) - 1) ||
395 (strpbrk(argv[0], "0123456789"))) {
396 fprintf(stderr, "%s: Illegal network interface prefix\n", prog);
399 strcpy(anr.asr_nif_pref, argv[0]);
403 * Validate interface count
406 nifs = strtoul(argv[0], &cp, 0);
407 if (errno != 0 || *cp != '\0' || nifs > MAX_NIFS) {
408 fprintf(stderr, "%s: Invalid interface count\n", prog);
411 anr.asr_nif_cnt = nifs;
414 * Make sure the resulting name won't be too long
416 sprintf(str, "%lu", nifs - 1);
417 if ((strlen(str) + strlen(anr.asr_nif_pref)) >
418 sizeof(anr.asr_nif_intf) - 1) {
419 fprintf(stderr, "%s: Network interface prefix too long\n", prog);
424 * Tell the kernel to do it
426 s = socket(AF_ATM, SOCK_DGRAM, 0);
430 if (ioctl(s, AIOCSET, (caddr_t)&anr) < 0) {
431 fprintf(stderr, "%s: ", prog);
432 perror("ioctl (AIOCSET) set NIF");
440 * Process set NSAP prefix command
443 * atm set nsap <interface_name> <NSAP prefix>
446 * argc number of remaining arguments to command
447 * argv pointer to remaining argument strings
448 * cmdp pointer to command description
455 set_prefix(int argc, char **argv, const struct cmd *cmdp __unused)
460 struct atmsetreq asr;
463 * Validate interface name
465 if (strlen(argv[0]) > sizeof(asr.asr_prf_intf) - 1) {
466 fprintf(stderr, "%s: Illegal interface name\n", prog);
473 * Get the prefix provided by the user
475 if (get_hex_atm_addr(argv[0], pfx, sizeof(pfx)) != sizeof(pfx)) {
476 fprintf(stderr, "%s: Invalid NSAP prefix\n", prog);
481 * Build ioctl request
483 asr.asr_opcode = AIOCS_SET_PRF;
484 strncpy(asr.asr_prf_intf, intf, sizeof(asr.asr_prf_intf));
485 bcopy(pfx, asr.asr_prf_pref, sizeof(asr.asr_prf_pref));
488 * Pass the new prefix to the kernel
490 s = socket(AF_ATM, SOCK_DGRAM, 0);
494 if (ioctl(s, AIOCSET, (caddr_t)&asr) < 0) {
495 fprintf(stderr, "%s: ", prog);
498 case EPROTONOSUPPORT:
499 perror("Internal error");
502 fprintf(stderr, "NSAP prefix is already set\n");
505 fprintf(stderr, "Invalid parameter\n");
508 fprintf(stderr, "Kernel memory exhausted\n");
511 fprintf(stderr, "ATM network is inoperable\n");
514 fprintf(stderr, "Must be super user to use set subcommand\n");
517 fprintf(stderr, "%s is not an ATM device\n",
521 perror("Ioctl (AIOCSET) NSAP prefix");