* K&R function cleanup
[dragonfly.git] / usr.sbin / atm / atmarpd / atmarp_config.c
1 /*
2  *
3  * ===================================
4  * HARP  |  Host ATM Research Platform
5  * ===================================
6  *
7  *
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.
12  *
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.
20  *
21  * Copyright 1994-1998 Network Computing Services, Inc.
22  *
23  * Copies of this Software may be made, however, the above copyright
24  * notice must be reproduced on all copies.
25  *
26  *      @(#) $FreeBSD: src/usr.sbin/atm/atmarpd/atmarp_config.c,v 1.3 1999/08/28 01:15:29 peter Exp $
27  *      @(#) $DragonFly: src/usr.sbin/atm/atmarpd/atmarp_config.c,v 1.3 2003/11/15 20:33:42 eirikn Exp $
28  */
29
30 /*
31  * Server Cache Synchronization Protocol (SCSP) Support
32  * ----------------------------------------------------
33  *
34  * SCSP-ATMARP server interface: configuration support
35  *
36  */
37
38 #include <sys/types.h>
39 #include <sys/param.h>
40 #include <sys/socket.h>
41 #include <net/if.h>
42 #include <netinet/in.h>
43 #include <netatm/port.h>
44 #include <netatm/queue.h>
45 #include <netatm/atm.h>
46 #include <netatm/atm_if.h>
47 #include <netatm/atm_sap.h>
48 #include <netatm/atm_sys.h>
49 #include <netatm/atm_ioctl.h>
50  
51 #include <errno.h>
52 #include <libatm.h>
53 #include <stdio.h>
54 #include <stdlib.h>
55 #include <string.h>
56 #include <syslog.h>
57
58 #include "../scspd/scsp_msg.h"
59 #include "../scspd/scsp_if.h"
60 #include "../scspd/scsp_var.h"
61 #include "atmarp_var.h"
62
63 /*
64  * Configure network interface for ATMARP cache synchronization
65  *
66  * Verify the network interface name and set the appropriate fields
67  * in the ATMARP interface entry.
68  *
69  * Arguments:
70  *      netif   pointer to network interface name
71  *
72  * Returns:
73  *      0       success
74  *      errno   reason for failure
75  *
76  */
77 int
78 atmarp_cfg_netif(char *netif)
79 {
80         int                     rc;
81         Atmarp_intf             *aip = (Atmarp_intf *)0;
82
83         /*
84          * Get an ATMARP interface block
85          */
86         aip = (Atmarp_intf *)UM_ALLOC(sizeof(Atmarp_intf));
87         if (!aip)
88                 atmarp_mem_err("atmarp_cfg_netif: sizeof(Atmarp_intf)");
89         UM_ZERO(aip, sizeof(Atmarp_intf));
90
91         /*
92          * Make sure we're configuring a valid
93          * network interface
94          */
95         rc = verify_nif_name(netif);
96         if (rc == 0) {
97                 fprintf(stderr, "%s: \"%s\" is not a valid network interface\n",
98                                 prog, netif);
99                 rc = EINVAL;
100                 goto cfg_fail;
101         } else if (rc < 0) {
102                 rc = errno;
103                 fprintf(stderr, "%s: can't verify network interface \"%s\"\n",
104                                 prog, netif);
105                 goto cfg_fail;
106         }
107
108         /*
109          * Update the interface entry
110          */
111         strcpy(aip->ai_intf, netif);
112         aip->ai_state = AI_STATE_NULL;
113         aip->ai_scsp_sock = -1;
114         LINK2TAIL(aip, Atmarp_intf, atmarp_intf_head, ai_next);
115
116         return(0);
117
118 cfg_fail:
119         if (aip)
120                 UM_FREE(aip);
121
122         return(rc);
123 }