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 $
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 __RCSID("@(#) $FreeBSD: src/sbin/atm/atm/atm_set.c,v 1.3.2.1 2000/07/01 06:02:14 ps Exp $");
65 * Process ATM ARP server set command
68 * atm set arpserver <interface_name> <atm-address> <IP prefix> ...
71 * argc number of arguments to command
72 * argv pointer to argument strings
73 * cmdp pointer to command description
80 set_arpserver(argc, argv, cmdp)
85 int i, len, prefix_len = 0, rc, s;
88 struct sockaddr_in *lis;
89 struct sockaddr_in if_mask;
92 struct air_netif_rsp *int_info;
94 struct in_addr ip_addr;
95 struct in_addr ip_mask;
99 * Validate interface name
101 check_netif_name(argv[0]);
106 * Get the ARP server's ATM address
108 UM_ZERO(&server, sizeof(server));
109 if (strcasecmp(argv[0], "local")) {
111 * ARP server NSAP address is provided
113 server.address_format = T_ATM_ENDSYS_ADDR;
114 server.address_length = sizeof(Atm_addr_nsap);
115 if (get_hex_atm_addr(argv[0],
116 (u_char *)server.address,
117 sizeof(Atm_addr_nsap)) !=
118 sizeof(Atm_addr_nsap)) {
119 fprintf(stderr, "%s: Invalid ARP server address\n",
124 fprintf(stderr, "%s: Invalid number of arguments\n",
133 * This host is the ARP server
135 server.address_format = T_ATM_ABSENT;
136 server.address_length = 0;
139 * Get interface information from the kernel. We need
140 * to get the IP address and the subnet mask associated
141 * with the network interface and insert them into the
142 * list of permitted LIS prefixes.
144 len = sizeof(struct air_netif_rsp);
145 UM_ZERO(&air, sizeof(air));
146 air.air_opcode = AIOCS_INF_NIF;
147 strcpy(air.air_int_intf, intf);
148 len = do_info_ioctl(&air, len);
150 fprintf(stderr, "%s: ", prog);
154 perror("Internal error");
157 fprintf(stderr, "%s is not an ATM device\n",
161 perror("ioctl (AIOCINFO)");
166 int_info = (struct air_netif_rsp *) air.air_buf_addr;
167 lis = (struct sockaddr_in *)&int_info->anp_proto_addr;
168 prefix_buf[0].ip_addr = lis->sin_addr;
171 rc = get_subnet_mask(intf, &if_mask);
173 fprintf(stderr, "%s: Can't get subnet mask for %s\n",
176 prefix_buf[0].ip_mask = if_mask.sin_addr;
177 prefix_buf[0].ip_addr.s_addr &=
178 prefix_buf[0].ip_mask.s_addr;
181 * Get the prefixes of the LISs that we'll support
183 for (i = 1; argc; i++, argc--, argv++) {
184 rc = parse_ip_prefix(argv[0],
185 (struct in_addr *)&prefix_buf[i]);
187 fprintf(stderr, "%s: Invalid IP prefix value \'%s\'\n",
194 * Compress the prefix list
196 prefix_len = compress_prefix_list((struct in_addr *)prefix_buf,
197 i * sizeof(struct in_addr) * 2);
201 * Build ioctl request
203 UM_ZERO(&asr, sizeof(asr));
204 asr.asr_opcode = AIOCS_SET_ASV;
205 strncpy(asr.asr_arp_intf, intf, sizeof(asr.asr_arp_intf));
206 asr.asr_arp_addr = server;
207 asr.asr_arp_subaddr.address_format = T_ATM_ABSENT;
208 asr.asr_arp_subaddr.address_length = 0;
210 asr.asr_arp_pbuf = (caddr_t)prefix_buf;
212 asr.asr_arp_pbuf = (caddr_t)0;
213 asr.asr_arp_plen = prefix_len;
216 * Pass the new ARP server address to the kernel
218 s = socket(AF_ATM, SOCK_DGRAM, 0);
222 if (ioctl(s, AIOCSET, (caddr_t)&asr) < 0) {
223 fprintf(stderr, "%s: ", prog);
226 case EPROTONOSUPPORT:
227 perror("Internal error");
230 fprintf(stderr, "Invalid parameter\n");
233 fprintf(stderr, "Kernel memory exhausted\n");
236 fprintf(stderr, "ATM network is inoperable\n");
239 fprintf(stderr, "Must be super user to use set subcommand\n");
242 fprintf(stderr, "%s is not an ATM interface\n", intf);
245 fprintf(stderr, "Signalling manager not attached\n");
249 "%s does not have an IP address configured\n",
253 perror("Ioctl (AIOCSET) ARPSERVER address");
264 * Process set MAC address command
267 * atm set mac <interface_name> <MAC address>
270 * argc number of remaining arguments to command
271 * argv pointer to remaining argument strings
272 * cmdp pointer to command description
279 set_macaddr(argc, argv, cmdp)
287 struct atmsetreq asr;
290 * Validate interface name
292 if (strlen(argv[0]) > sizeof(asr.asr_mac_intf) - 1) {
293 fprintf(stderr, "%s: Illegal interface name\n", prog);
300 * Get the MAC address provided by the user
302 if (get_hex_atm_addr(argv[0], (u_char *)&mac, sizeof(mac)) !=
304 fprintf(stderr, "%s: Invalid MAC address\n", prog);
309 * Build ioctl request
311 asr.asr_opcode = AIOCS_SET_MAC;
312 strncpy(asr.asr_mac_intf, intf, sizeof(asr.asr_mac_intf));
313 UM_COPY(&mac, &asr.asr_mac_addr, sizeof(asr.asr_mac_addr));
316 * Pass the new address to the kernel
318 s = socket(AF_ATM, SOCK_DGRAM, 0);
322 if (ioctl(s, AIOCSET, (caddr_t)&asr) < 0) {
323 fprintf(stderr, "%s: ", prog);
326 case EPROTONOSUPPORT:
327 perror("Internal error");
330 fprintf(stderr, "Interface must be detached to set MAC addres\n");
333 fprintf(stderr, "Invalid parameter\n");
336 fprintf(stderr, "Kernel memory exhausted\n");
339 fprintf(stderr, "ATM network is inoperable\n");
342 fprintf(stderr, "Must be super user to use set subcommand\n");
345 fprintf(stderr, "%s is not an ATM device\n",
349 perror("Ioctl (AIOCSET) MAC address");
360 * Process network interface set command
363 * atm set netif <interface_name> <prefix_name> <count>
366 * argc number of arguments to command
367 * argv pointer to argument strings
368 * cmdp pointer to command description
375 set_netif(argc, argv, cmdp)
380 struct atmsetreq anr;
388 anr.asr_opcode = AIOCS_SET_NIF;
391 * Validate interface name
393 if (strlen(argv[0]) > sizeof(anr.asr_nif_intf) - 1) {
394 fprintf(stderr, "%s: Illegal interface name\n", prog);
397 strcpy(anr.asr_nif_intf, argv[0]);
401 * Validate network interface name prefix
403 if ((strlen(argv[0]) > sizeof(anr.asr_nif_pref) - 1) ||
404 (strpbrk(argv[0], "0123456789"))) {
405 fprintf(stderr, "%s: Illegal network interface prefix\n", prog);
408 strcpy(anr.asr_nif_pref, argv[0]);
412 * Validate interface count
414 nifs = (int) strtol(argv[0], &cp, 0);
415 if ((*cp != '\0') || (nifs < 0) || (nifs > MAX_NIFS)) {
416 fprintf(stderr, "%s: Invalid interface count\n", prog);
419 anr.asr_nif_cnt = nifs;
422 * Make sure the resulting name won't be too long
424 sprintf(str, "%d", nifs - 1);
425 if ((strlen(str) + strlen(anr.asr_nif_pref)) >
426 sizeof(anr.asr_nif_intf) - 1) {
427 fprintf(stderr, "%s: Network interface prefix too long\n", prog);
432 * Tell the kernel to do it
434 s = socket(AF_ATM, SOCK_DGRAM, 0);
438 if (ioctl(s, AIOCSET, (caddr_t)&anr) < 0) {
439 fprintf(stderr, "%s: ", prog);
440 perror("ioctl (AIOCSET) set NIF");
448 * Process set NSAP prefix command
451 * atm set nsap <interface_name> <NSAP prefix>
454 * argc number of remaining arguments to command
455 * argv pointer to remaining argument strings
456 * cmdp pointer to command description
463 set_prefix(argc, argv, cmdp)
471 struct atmsetreq asr;
474 * Validate interface name
476 if (strlen(argv[0]) > sizeof(asr.asr_prf_intf) - 1) {
477 fprintf(stderr, "%s: Illegal interface name\n", prog);
484 * Get the prefix provided by the user
486 if (get_hex_atm_addr(argv[0], prefix, sizeof(prefix)) !=
488 fprintf(stderr, "%s: Invalid NSAP prefix\n", prog);
493 * Build ioctl request
495 asr.asr_opcode = AIOCS_SET_PRF;
496 strncpy(asr.asr_prf_intf, intf, sizeof(asr.asr_prf_intf));
497 UM_COPY(prefix, asr.asr_prf_pref, sizeof(asr.asr_prf_pref));
500 * Pass the new prefix to the kernel
502 s = socket(AF_ATM, SOCK_DGRAM, 0);
506 if (ioctl(s, AIOCSET, (caddr_t)&asr) < 0) {
507 fprintf(stderr, "%s: ", prog);
510 case EPROTONOSUPPORT:
511 perror("Internal error");
514 fprintf(stderr, "NSAP prefix is already set\n");
517 fprintf(stderr, "Invalid parameter\n");
520 fprintf(stderr, "Kernel memory exhausted\n");
523 fprintf(stderr, "ATM network is inoperable\n");
526 fprintf(stderr, "Must be super user to use set subcommand\n");
529 fprintf(stderr, "%s is not an ATM device\n",
533 perror("Ioctl (AIOCSET) NSAP prefix");