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.
31 * Server Cache Synchronization Protocol (SCSP) Support
32 * ----------------------------------------------------
34 * SCSP-ATMARP server interface: main line code
38 #include <sys/types.h>
39 #include <sys/param.h>
40 #include <sys/socket.h>
42 #include <sys/ttycom.h>
44 #include <netinet/in.h>
45 #include <netatm/queue.h>
46 #include <netatm/atm.h>
47 #include <netatm/atm_if.h>
48 #include <netatm/atm_sap.h>
49 #include <netatm/atm_sys.h>
50 #include <netatm/atm_ioctl.h>
61 #include "../scspd/scsp_msg.h"
62 #include "../scspd/scsp_if.h"
63 #include "../scspd/scsp_var.h"
64 #include "atmarp_var.h"
67 __RCSID("@(#) $FreeBSD$");
75 int atmarp_debug_mode = 0;
76 int atmarp_max_socket = 0;
77 Atmarp_intf *atmarp_intf_head = (Atmarp_intf *)0;
78 Atmarp_slis *atmarp_slis_head = (Atmarp_slis *)0;
79 FILE *atmarp_log_file = (FILE *)0;
80 char *atmarp_log_file_name = (char *)0;
81 Harp_timer cache_timer, perm_timer;
85 * Print a usage message
91 * exits, does not return
97 fprintf(stderr, "usage: %s [-d] [-l <log_file>] <net_intf> ...\n", prog);
103 * Process command line parameters
106 * argc number of command-line arguments
107 * argv list of pointers to command-line arguments
114 initialize(argc, argv)
122 * Save program name, ignoring any path components
124 if ((prog = (char *)strrchr(argv[0], '/')) != NULL)
130 * Make sure we're being invoked by the super user
134 fprintf(stderr, "%s: You must be root to run this program\n",
140 * Scan arguments, checking for options
142 for (i = 1; i < argc; i++) {
143 if (argv[i][0] == '-') {
144 if (strcmp(argv[i], "-d") == 0) {
145 atmarp_debug_mode = TRUE;
146 } else if (strcmp(argv[i], "-l") == 0) {
149 fprintf(stderr, "%s: Log file name missing\n",
153 atmarp_log_file_name = argv[i];
155 fprintf(stderr, "%s: Unrecognized option \"%s\"\n",
161 * Parameter is a network interface name
163 rc = atmarp_cfg_netif(argv[i]);
165 fprintf(stderr, "%s: Error configuring network interface %s\n",
173 * Make sure we had at least one interface configured
175 if (!atmarp_intf_head) {
182 * Daemon housekeeping
195 int dpid, fd, file_count, rc;
198 * Ignore selected signals
201 signal(SIGTTOU, SIG_IGN);
204 signal(SIGTTIN, SIG_IGN);
207 signal(SIGTSTP, SIG_IGN);
210 signal(SIGPIPE, SIG_IGN);
214 * Skip putting things into the background if we're
217 if (atmarp_debug_mode)
221 * Set up syslog for error logging
223 if (!atmarp_log_file) {
224 openlog(prog, LOG_PID | LOG_CONS, LOG_DAEMON);
228 * Put the daemon into the background
232 atmarp_log(LOG_ERR, "fork failed");
237 * This is the parent process--just exit and let
238 * the daughter do all the work
244 * Disassociate from any controlling terminal
246 rc = setpgrp(0, getpid());
248 atmarp_log(LOG_ERR, "can't change process group");
251 fd = open(_PATH_TTY, O_RDWR);
253 ioctl(fd, TIOCNOTTY, (char *)0);
258 * Close all open file descriptors
260 file_count = getdtablesize();
261 for (fd=0; fd<file_count; fd++) {
266 * Open log file, if specified
268 if (atmarp_log_file_name) {
269 atmarp_log_file = fopen(atmarp_log_file_name, "a");
270 if (!atmarp_log_file) {
271 atmarp_log(LOG_ERR, "%s: Can't open log file \'%s\'\n",
272 prog, atmarp_log_file_name);
278 * Set up and start interval timer
284 * Move to a safe directory
289 * Clear the file mode creation mask
295 * Set up signal handlers
297 rc = (int)signal(SIGINT, atmarp_sigint);
299 atmarp_log(LOG_ERR, "SIGINT signal setup failed");
308 * The ATMARP server resides in the kernel, while SCSP runs as a daemon
309 * in user space. This program exists to provide an interface between
310 * the two. It periodically polls the kernel to get the ATMARP cache
311 * and passes information about new entries to SCSP. It also accepts
312 * new information from SCSP and passes it to the kernel.
315 * argc number of command-line arguments
316 * argv list of pointers to command-line arguments
329 fd_set read_set, write_set, except_set;
333 * Process command line arguments
335 initialize(argc, argv);
338 * Put the daemon into the background
343 * Start the cache update timer
345 HARP_TIMER(&cache_timer, ATMARP_CACHE_INTERVAL,
346 atmarp_cache_timeout);
349 * Start the permanent cache entry timer
351 HARP_TIMER(&perm_timer, ATMARP_PERM_INTERVAL,
352 atmarp_perm_timeout);
355 * Establish a connection to SCSP for each interface. If a
356 * connect fails, it will be retried when the cache update
359 for (aip = atmarp_intf_head; aip; aip = aip->ai_next) {
360 if (atmarp_if_ready(aip)) {
361 (void)atmarp_scsp_connect(aip);
366 * Read the cache from the kernel
368 atmarp_get_updated_cache();
371 * Main program loop -- wait for data to come in from SCSP.
372 * When the timer fires, it will be handled elsewhere.
376 * Wait for input from SCSP
380 FD_ZERO(&except_set);
381 for (aip = atmarp_intf_head; aip; aip = aip->ai_next) {
382 if (aip->ai_scsp_sock != -1) {
383 FD_SET(aip->ai_scsp_sock, &read_set);
386 rc = select(atmarp_max_socket + 1,
387 &read_set, &write_set,
388 &except_set, (struct timeval *)0);
390 if (harp_timer_exec) {
393 } else if (errno == EINTR) {
396 atmarp_log(LOG_ERR, "Select failed");
402 * Read and process the input from SCSP
404 for (i = 0; i <= atmarp_max_socket; i++) {
405 if (FD_ISSET(i, &read_set)) {
406 aip = atmarp_find_intf_sock(i);
408 rc = atmarp_scsp_read(aip);