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.3 2003/09/28 14:39:16 hmp 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(int argc, char **argv, struct cmd *cmdp)
77 int i, len, prefix_len = 0, rc, s;
80 struct sockaddr_in *lis;
81 struct sockaddr_in if_mask;
84 struct air_netif_rsp *int_info;
86 struct in_addr ip_addr;
87 struct in_addr ip_mask;
91 * Validate interface name
93 check_netif_name(argv[0]);
98 * Get the ARP server's ATM address
100 UM_ZERO(&server, sizeof(server));
101 if (strcasecmp(argv[0], "local")) {
103 * ARP server NSAP address is provided
105 server.address_format = T_ATM_ENDSYS_ADDR;
106 server.address_length = sizeof(Atm_addr_nsap);
107 if (get_hex_atm_addr(argv[0],
108 (u_char *)server.address,
109 sizeof(Atm_addr_nsap)) !=
110 sizeof(Atm_addr_nsap)) {
111 fprintf(stderr, "%s: Invalid ARP server address\n",
116 fprintf(stderr, "%s: Invalid number of arguments\n",
125 * This host is the ARP server
127 server.address_format = T_ATM_ABSENT;
128 server.address_length = 0;
131 * Get interface information from the kernel. We need
132 * to get the IP address and the subnet mask associated
133 * with the network interface and insert them into the
134 * list of permitted LIS prefixes.
136 len = sizeof(struct air_netif_rsp);
137 UM_ZERO(&air, sizeof(air));
138 air.air_opcode = AIOCS_INF_NIF;
139 strcpy(air.air_int_intf, intf);
140 len = do_info_ioctl(&air, len);
142 fprintf(stderr, "%s: ", prog);
146 perror("Internal error");
149 fprintf(stderr, "%s is not an ATM device\n",
153 perror("ioctl (AIOCINFO)");
158 int_info = (struct air_netif_rsp *) air.air_buf_addr;
159 lis = (struct sockaddr_in *)&int_info->anp_proto_addr;
160 prefix_buf[0].ip_addr = lis->sin_addr;
163 rc = get_subnet_mask(intf, &if_mask);
165 fprintf(stderr, "%s: Can't get subnet mask for %s\n",
168 prefix_buf[0].ip_mask = if_mask.sin_addr;
169 prefix_buf[0].ip_addr.s_addr &=
170 prefix_buf[0].ip_mask.s_addr;
173 * Get the prefixes of the LISs that we'll support
175 for (i = 1; argc; i++, argc--, argv++) {
176 rc = parse_ip_prefix(argv[0],
177 (struct in_addr *)&prefix_buf[i]);
179 fprintf(stderr, "%s: Invalid IP prefix value \'%s\'\n",
186 * Compress the prefix list
188 prefix_len = compress_prefix_list((struct in_addr *)prefix_buf,
189 i * sizeof(struct in_addr) * 2);
193 * Build ioctl request
195 UM_ZERO(&asr, sizeof(asr));
196 asr.asr_opcode = AIOCS_SET_ASV;
197 strncpy(asr.asr_arp_intf, intf, sizeof(asr.asr_arp_intf));
198 asr.asr_arp_addr = server;
199 asr.asr_arp_subaddr.address_format = T_ATM_ABSENT;
200 asr.asr_arp_subaddr.address_length = 0;
202 asr.asr_arp_pbuf = (caddr_t)prefix_buf;
204 asr.asr_arp_pbuf = (caddr_t)0;
205 asr.asr_arp_plen = prefix_len;
208 * Pass the new ARP server address to the kernel
210 s = socket(AF_ATM, SOCK_DGRAM, 0);
214 if (ioctl(s, AIOCSET, (caddr_t)&asr) < 0) {
215 fprintf(stderr, "%s: ", prog);
218 case EPROTONOSUPPORT:
219 perror("Internal error");
222 fprintf(stderr, "Invalid parameter\n");
225 fprintf(stderr, "Kernel memory exhausted\n");
228 fprintf(stderr, "ATM network is inoperable\n");
231 fprintf(stderr, "Must be super user to use set subcommand\n");
234 fprintf(stderr, "%s is not an ATM interface\n", intf);
237 fprintf(stderr, "Signalling manager not attached\n");
241 "%s does not have an IP address configured\n",
245 perror("Ioctl (AIOCSET) ARPSERVER address");
256 * Process set MAC address command
259 * atm set mac <interface_name> <MAC address>
262 * argc number of remaining arguments to command
263 * argv pointer to remaining argument strings
264 * cmdp pointer to command description
271 set_macaddr(int argc, char **argv, struct cmd *cmdp)
276 struct atmsetreq asr;
279 * Validate interface name
281 if (strlen(argv[0]) > sizeof(asr.asr_mac_intf) - 1) {
282 fprintf(stderr, "%s: Illegal interface name\n", prog);
289 * Get the MAC address provided by the user
291 if (get_hex_atm_addr(argv[0], (u_char *)&mac, sizeof(mac)) !=
293 fprintf(stderr, "%s: Invalid MAC address\n", prog);
298 * Build ioctl request
300 asr.asr_opcode = AIOCS_SET_MAC;
301 strncpy(asr.asr_mac_intf, intf, sizeof(asr.asr_mac_intf));
302 UM_COPY(&mac, &asr.asr_mac_addr, sizeof(asr.asr_mac_addr));
305 * Pass the new address to the kernel
307 s = socket(AF_ATM, SOCK_DGRAM, 0);
311 if (ioctl(s, AIOCSET, (caddr_t)&asr) < 0) {
312 fprintf(stderr, "%s: ", prog);
315 case EPROTONOSUPPORT:
316 perror("Internal error");
319 fprintf(stderr, "Interface must be detached to set MAC addres\n");
322 fprintf(stderr, "Invalid parameter\n");
325 fprintf(stderr, "Kernel memory exhausted\n");
328 fprintf(stderr, "ATM network is inoperable\n");
331 fprintf(stderr, "Must be super user to use set subcommand\n");
334 fprintf(stderr, "%s is not an ATM device\n",
338 perror("Ioctl (AIOCSET) MAC address");
349 * Process network interface set command
352 * atm set netif <interface_name> <prefix_name> <count>
355 * argc number of arguments to command
356 * argv pointer to argument strings
357 * cmdp pointer to command description
364 set_netif(int argc, char **argv, struct cmd *cmdp)
366 struct atmsetreq anr;
374 anr.asr_opcode = AIOCS_SET_NIF;
377 * Validate interface name
379 if (strlen(argv[0]) > sizeof(anr.asr_nif_intf) - 1) {
380 fprintf(stderr, "%s: Illegal interface name\n", prog);
383 strcpy(anr.asr_nif_intf, argv[0]);
387 * Validate network interface name prefix
389 if ((strlen(argv[0]) > sizeof(anr.asr_nif_pref) - 1) ||
390 (strpbrk(argv[0], "0123456789"))) {
391 fprintf(stderr, "%s: Illegal network interface prefix\n", prog);
394 strcpy(anr.asr_nif_pref, argv[0]);
398 * Validate interface count
400 nifs = (int) strtol(argv[0], &cp, 0);
401 if ((*cp != '\0') || (nifs < 0) || (nifs > MAX_NIFS)) {
402 fprintf(stderr, "%s: Invalid interface count\n", prog);
405 anr.asr_nif_cnt = nifs;
408 * Make sure the resulting name won't be too long
410 sprintf(str, "%d", nifs - 1);
411 if ((strlen(str) + strlen(anr.asr_nif_pref)) >
412 sizeof(anr.asr_nif_intf) - 1) {
413 fprintf(stderr, "%s: Network interface prefix too long\n", prog);
418 * Tell the kernel to do it
420 s = socket(AF_ATM, SOCK_DGRAM, 0);
424 if (ioctl(s, AIOCSET, (caddr_t)&anr) < 0) {
425 fprintf(stderr, "%s: ", prog);
426 perror("ioctl (AIOCSET) set NIF");
434 * Process set NSAP prefix command
437 * atm set nsap <interface_name> <NSAP prefix>
440 * argc number of remaining arguments to command
441 * argv pointer to remaining argument strings
442 * cmdp pointer to command description
449 set_prefix(int argc, char **argv, struct cmd *cmdp)
454 struct atmsetreq asr;
457 * Validate interface name
459 if (strlen(argv[0]) > sizeof(asr.asr_prf_intf) - 1) {
460 fprintf(stderr, "%s: Illegal interface name\n", prog);
467 * Get the prefix provided by the user
469 if (get_hex_atm_addr(argv[0], prefix, sizeof(prefix)) !=
471 fprintf(stderr, "%s: Invalid NSAP prefix\n", prog);
476 * Build ioctl request
478 asr.asr_opcode = AIOCS_SET_PRF;
479 strncpy(asr.asr_prf_intf, intf, sizeof(asr.asr_prf_intf));
480 UM_COPY(prefix, asr.asr_prf_pref, sizeof(asr.asr_prf_pref));
483 * Pass the new prefix to the kernel
485 s = socket(AF_ATM, SOCK_DGRAM, 0);
489 if (ioctl(s, AIOCSET, (caddr_t)&asr) < 0) {
490 fprintf(stderr, "%s: ", prog);
493 case EPROTONOSUPPORT:
494 perror("Internal error");
497 fprintf(stderr, "NSAP prefix is already set\n");
500 fprintf(stderr, "Invalid parameter\n");
503 fprintf(stderr, "Kernel memory exhausted\n");
506 fprintf(stderr, "ATM network is inoperable\n");
509 fprintf(stderr, "Must be super user to use set subcommand\n");
512 fprintf(stderr, "%s is not an ATM device\n",
516 perror("Ioctl (AIOCSET) NSAP prefix");