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.
26 * @(#) $FreeBSD: src/sbin/atm/atm/atm_set.c,v 1.3.2.1 2000/07/01 06:02:14 ps Exp $
27 * @(#) $DragonFly: src/sbin/atm/atm/atm_set.c,v 1.2 2003/06/17 04:27:32 dillon Exp $
31 * User configuration and display program
32 * --------------------------------------
34 * Routines for "set" subcommand
38 #include <sys/param.h>
39 #include <sys/socket.h>
40 #include <sys/sockio.h>
42 #include <netinet/in.h>
43 #include <netatm/port.h>
44 #include <netatm/atm.h>
45 #include <netatm/atm_if.h>
46 #include <netatm/atm_sap.h>
47 #include <netatm/atm_sys.h>
48 #include <netatm/atm_ioctl.h>
60 * Process ATM ARP server set command
63 * atm set arpserver <interface_name> <atm-address> <IP prefix> ...
66 * argc number of arguments to command
67 * argv pointer to argument strings
68 * cmdp pointer to command description
75 set_arpserver(argc, argv, cmdp)
80 int i, len, prefix_len = 0, rc, s;
83 struct sockaddr_in *lis;
84 struct sockaddr_in if_mask;
87 struct air_netif_rsp *int_info;
89 struct in_addr ip_addr;
90 struct in_addr ip_mask;
94 * Validate interface name
96 check_netif_name(argv[0]);
101 * Get the ARP server's ATM address
103 UM_ZERO(&server, sizeof(server));
104 if (strcasecmp(argv[0], "local")) {
106 * ARP server NSAP address is provided
108 server.address_format = T_ATM_ENDSYS_ADDR;
109 server.address_length = sizeof(Atm_addr_nsap);
110 if (get_hex_atm_addr(argv[0],
111 (u_char *)server.address,
112 sizeof(Atm_addr_nsap)) !=
113 sizeof(Atm_addr_nsap)) {
114 fprintf(stderr, "%s: Invalid ARP server address\n",
119 fprintf(stderr, "%s: Invalid number of arguments\n",
128 * This host is the ARP server
130 server.address_format = T_ATM_ABSENT;
131 server.address_length = 0;
134 * Get interface information from the kernel. We need
135 * to get the IP address and the subnet mask associated
136 * with the network interface and insert them into the
137 * list of permitted LIS prefixes.
139 len = sizeof(struct air_netif_rsp);
140 UM_ZERO(&air, sizeof(air));
141 air.air_opcode = AIOCS_INF_NIF;
142 strcpy(air.air_int_intf, intf);
143 len = do_info_ioctl(&air, len);
145 fprintf(stderr, "%s: ", prog);
149 perror("Internal error");
152 fprintf(stderr, "%s is not an ATM device\n",
156 perror("ioctl (AIOCINFO)");
161 int_info = (struct air_netif_rsp *) air.air_buf_addr;
162 lis = (struct sockaddr_in *)&int_info->anp_proto_addr;
163 prefix_buf[0].ip_addr = lis->sin_addr;
166 rc = get_subnet_mask(intf, &if_mask);
168 fprintf(stderr, "%s: Can't get subnet mask for %s\n",
171 prefix_buf[0].ip_mask = if_mask.sin_addr;
172 prefix_buf[0].ip_addr.s_addr &=
173 prefix_buf[0].ip_mask.s_addr;
176 * Get the prefixes of the LISs that we'll support
178 for (i = 1; argc; i++, argc--, argv++) {
179 rc = parse_ip_prefix(argv[0],
180 (struct in_addr *)&prefix_buf[i]);
182 fprintf(stderr, "%s: Invalid IP prefix value \'%s\'\n",
189 * Compress the prefix list
191 prefix_len = compress_prefix_list((struct in_addr *)prefix_buf,
192 i * sizeof(struct in_addr) * 2);
196 * Build ioctl request
198 UM_ZERO(&asr, sizeof(asr));
199 asr.asr_opcode = AIOCS_SET_ASV;
200 strncpy(asr.asr_arp_intf, intf, sizeof(asr.asr_arp_intf));
201 asr.asr_arp_addr = server;
202 asr.asr_arp_subaddr.address_format = T_ATM_ABSENT;
203 asr.asr_arp_subaddr.address_length = 0;
205 asr.asr_arp_pbuf = (caddr_t)prefix_buf;
207 asr.asr_arp_pbuf = (caddr_t)0;
208 asr.asr_arp_plen = prefix_len;
211 * Pass the new ARP server address to the kernel
213 s = socket(AF_ATM, SOCK_DGRAM, 0);
217 if (ioctl(s, AIOCSET, (caddr_t)&asr) < 0) {
218 fprintf(stderr, "%s: ", prog);
221 case EPROTONOSUPPORT:
222 perror("Internal error");
225 fprintf(stderr, "Invalid parameter\n");
228 fprintf(stderr, "Kernel memory exhausted\n");
231 fprintf(stderr, "ATM network is inoperable\n");
234 fprintf(stderr, "Must be super user to use set subcommand\n");
237 fprintf(stderr, "%s is not an ATM interface\n", intf);
240 fprintf(stderr, "Signalling manager not attached\n");
244 "%s does not have an IP address configured\n",
248 perror("Ioctl (AIOCSET) ARPSERVER address");
259 * Process set MAC address command
262 * atm set mac <interface_name> <MAC address>
265 * argc number of remaining arguments to command
266 * argv pointer to remaining argument strings
267 * cmdp pointer to command description
274 set_macaddr(argc, argv, cmdp)
282 struct atmsetreq asr;
285 * Validate interface name
287 if (strlen(argv[0]) > sizeof(asr.asr_mac_intf) - 1) {
288 fprintf(stderr, "%s: Illegal interface name\n", prog);
295 * Get the MAC address provided by the user
297 if (get_hex_atm_addr(argv[0], (u_char *)&mac, sizeof(mac)) !=
299 fprintf(stderr, "%s: Invalid MAC address\n", prog);
304 * Build ioctl request
306 asr.asr_opcode = AIOCS_SET_MAC;
307 strncpy(asr.asr_mac_intf, intf, sizeof(asr.asr_mac_intf));
308 UM_COPY(&mac, &asr.asr_mac_addr, sizeof(asr.asr_mac_addr));
311 * Pass the new address to the kernel
313 s = socket(AF_ATM, SOCK_DGRAM, 0);
317 if (ioctl(s, AIOCSET, (caddr_t)&asr) < 0) {
318 fprintf(stderr, "%s: ", prog);
321 case EPROTONOSUPPORT:
322 perror("Internal error");
325 fprintf(stderr, "Interface must be detached to set MAC addres\n");
328 fprintf(stderr, "Invalid parameter\n");
331 fprintf(stderr, "Kernel memory exhausted\n");
334 fprintf(stderr, "ATM network is inoperable\n");
337 fprintf(stderr, "Must be super user to use set subcommand\n");
340 fprintf(stderr, "%s is not an ATM device\n",
344 perror("Ioctl (AIOCSET) MAC address");
355 * Process network interface set command
358 * atm set netif <interface_name> <prefix_name> <count>
361 * argc number of arguments to command
362 * argv pointer to argument strings
363 * cmdp pointer to command description
370 set_netif(argc, argv, cmdp)
375 struct atmsetreq anr;
383 anr.asr_opcode = AIOCS_SET_NIF;
386 * Validate interface name
388 if (strlen(argv[0]) > sizeof(anr.asr_nif_intf) - 1) {
389 fprintf(stderr, "%s: Illegal interface name\n", prog);
392 strcpy(anr.asr_nif_intf, argv[0]);
396 * Validate network interface name prefix
398 if ((strlen(argv[0]) > sizeof(anr.asr_nif_pref) - 1) ||
399 (strpbrk(argv[0], "0123456789"))) {
400 fprintf(stderr, "%s: Illegal network interface prefix\n", prog);
403 strcpy(anr.asr_nif_pref, argv[0]);
407 * Validate interface count
409 nifs = (int) strtol(argv[0], &cp, 0);
410 if ((*cp != '\0') || (nifs < 0) || (nifs > MAX_NIFS)) {
411 fprintf(stderr, "%s: Invalid interface count\n", prog);
414 anr.asr_nif_cnt = nifs;
417 * Make sure the resulting name won't be too long
419 sprintf(str, "%d", nifs - 1);
420 if ((strlen(str) + strlen(anr.asr_nif_pref)) >
421 sizeof(anr.asr_nif_intf) - 1) {
422 fprintf(stderr, "%s: Network interface prefix too long\n", prog);
427 * Tell the kernel to do it
429 s = socket(AF_ATM, SOCK_DGRAM, 0);
433 if (ioctl(s, AIOCSET, (caddr_t)&anr) < 0) {
434 fprintf(stderr, "%s: ", prog);
435 perror("ioctl (AIOCSET) set NIF");
443 * Process set NSAP prefix command
446 * atm set nsap <interface_name> <NSAP prefix>
449 * argc number of remaining arguments to command
450 * argv pointer to remaining argument strings
451 * cmdp pointer to command description
458 set_prefix(argc, argv, cmdp)
466 struct atmsetreq asr;
469 * Validate interface name
471 if (strlen(argv[0]) > sizeof(asr.asr_prf_intf) - 1) {
472 fprintf(stderr, "%s: Illegal interface name\n", prog);
479 * Get the prefix provided by the user
481 if (get_hex_atm_addr(argv[0], prefix, sizeof(prefix)) !=
483 fprintf(stderr, "%s: Invalid NSAP prefix\n", prog);
488 * Build ioctl request
490 asr.asr_opcode = AIOCS_SET_PRF;
491 strncpy(asr.asr_prf_intf, intf, sizeof(asr.asr_prf_intf));
492 UM_COPY(prefix, asr.asr_prf_pref, sizeof(asr.asr_prf_pref));
495 * Pass the new prefix to the kernel
497 s = socket(AF_ATM, SOCK_DGRAM, 0);
501 if (ioctl(s, AIOCSET, (caddr_t)&asr) < 0) {
502 fprintf(stderr, "%s: ", prog);
505 case EPROTONOSUPPORT:
506 perror("Internal error");
509 fprintf(stderr, "NSAP prefix is already set\n");
512 fprintf(stderr, "Invalid parameter\n");
515 fprintf(stderr, "Kernel memory exhausted\n");
518 fprintf(stderr, "ATM network is inoperable\n");
521 fprintf(stderr, "Must be super user to use set subcommand\n");
524 fprintf(stderr, "%s is not an ATM device\n",
528 perror("Ioctl (AIOCSET) NSAP prefix");