98N/A * CDDL HEADER START 98N/A * The contents of this file are subject to the terms of the 606N/A * Common Development and Distribution License, Version 1.0 only 761N/A * (the "License"). You may not use this file except in compliance 98N/A * with the License. 98N/A * See the License for the specific language governing permissions 98N/A * and limitations under the License. 98N/A * When distributing Covered Code, include this CDDL HEADER in each 98N/A * If applicable, add the following below this CDDL HEADER, with the 98N/A * fields enclosed by brackets "[]" replaced with your own identifying 98N/A * information: Portions Copyright [yyyy] [name of copyright owner] 98N/A * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 98N/A * Use is subject to license terms. 98N/A#
pragma ident "%Z%%M% %I% %E% SMI" 98N/A/* NCA does not support IPv6... */ 761N/A/* Structure to hold info about each network interface. */ /* The network interface array. */ /* Number of network interface to process. */ /* Interface request to IP. */ /* True if syslog is to be used. */ /* True if additional debugging messages are printed. */ /* File descriptor to the routing socket. */ * Print out system error messages, either to syslog or stderr. Note that * syslog() should print out system error messages in the correct language * used. There is no need to use gettext(). * Print out warning messages. The caller should use gettext() to have * the message printed out in the correct language. * Print out debugging info. Note that syslogd(1M) should be configured to * take ordinary debug info for it to get this kind of info. * Helper function for nca_setup(). It gets a fd to the lower IP * stream and I_PUNLINK's the lower stream. It also initializes the * int *udp_fd: (referenced) fd to /dev/udp (upper IP stream). * int *fd: (referenced) fd to the lower IP stream. * -1 if operation fails, 0 otherwise. * Helper function for nca_setup(). It I_PLINK's back the upper and * lower IP streams. Note that this function must be called after * ip_domux2fd(). In ip_domux2fd(), the global variable lifr is initialized * and ip_plink() needs information in lifr. So ip_domux2fd() and ip_plink() * must be called in pairs. * int udp_fd: fd to /dev/udp (upper IP stream). * int fd: fd to the lower IP stream. * Find the proper position to insert NCA, which is just below IP. * int fd: fd to the lower IP stream. * If positive, it is the position to insert NCA. * FOUND_NCA: found NCA! So skip this one for plumbing. But we * still keep it in the interface list. * FOUND_NONE: could not find IP or encounter other errors. Remove * this interface from the list. * NCA should be just below logdebug(
"NCA is at position %d in the stream.\n",
pos);
* To set the local IP address and default router ethernet address. * int fd: the fd to the lower IP stream. * struct in_addr local_addr: the IP address for this interface. * uchar_t *ether_addr: the ethernet address of the default router for * -1 if the system does not support this NCA ioctl(), 0 otherwise. * To setup the NCA stream. First insert NCA into the proper position. * Then tell NCA the local IP address and default router by using the * boolean_t *active: (referenced) B_TRUE if NCA is setup to do active * connection. If NCA does not support active connection, * in return, active will be set to B_FALSE. /* 128 is enough because interface name can only be LIFNAMSIZ long. */ /* This interface does not exist according to IP. */ /* Just skip plumbing NCA. */ * Only do the following if NCA is also used to make * outgoing connections, and all necessary info is * The system does not support this ioctl()! * Skip all active stack processing but logwarn(
"NCA does not support active stack!");
* To get IP address of network interface from IP. /* NCA only supports IPv4... */ * NCA is set up after all the interfaces have been * plumbed. So normally we should not get any error. * Just abort if we encounter an error. /* Find the interface and copy the local IP address. */ /* Again, NCA only supports IPv4. */ * The interface does not exist according to IP! * Log a warning and go on. * Set local_addr to 0 so that nca_setup() will * not do anything for this interface. * int sd: descriptor to IP to send down mib request. * Each reply consists of a ctl part for one fixed structure * or table, as defined in mib2.h. The format is a T_OPTMGMT_ACK, * containing an opthdr structure. level/name identify the entry, * len is the size of the data part of the message. (
void)
printf(
"%d %4d %5d %d\n",
"EOD (level %ld, name %ld)\n",
logwarn(
"mibget %d gives T_ERROR_ACK: TLI_error =" " 0x%lx, UNIX_error = 0x%lx\n",
logwarn(
"mibget getmsg(ctl) %d returned %d, " "ctlbuf.len = %d, PRIM_type = %ld\n",
"MGMT_flags = 0x%lx, req->len = %ld\n",
logwarn(
"mibget getmsg(data) returned %d, " "databuf.maxlen = %d, databuf.len = %d\n",
* Examine the IPv4 routing table for default routers. For each interface, * find its default router. * mib2_ipRouteEntry_t *buf: the mib info buffer. * size_t len: length of buffer. * boolean_t *changed (referenced): set to B_TRUE if there is a change * number of default router found. * Loop thru the routing table entries. Process any * IRE_DEFAULT ire. Ignore the others. For each such * ire, get the nexthop gateway address. * NCA is only interested in default routes associated /* Get the nexthop address. */ * Right now, not all IREs have the interface name * We don't have the outgoing interface in * this case. Get the nexthop address. Then * determine the outgoing interface, by * examining all interface IREs, and * Determine the interface IRE that * matches the nexthop. i.e. * (IRE addr & IRE mask) == * We found the interface to go to * the default router. Check the /* Can this be possible?? */ }
/* End inner for loop. */ /* We are sure both are NULL terminated. */ /* No change, do not do anything. */ " router for %s: %s\n",
ifname,
* The interface does not have a default router. * Log a warning and go on. " does not have a default router.\n"),
* Set router_addr to 0 so that we will * not do anything for this interface. * Examine the ARP table to find ethernet address for default routers. * mib2_ipNetToMdeiaEntry_t *buf: the mib info buffer. * size_t len: length of buffer. * boolean_t *changed (referenced): set to B_TRUE if there is any change * in ethernet address for any default router. * number of ethernet address found. * Loop thru the arp table entries and find the ethernet * address of those default routers. * Sanity check. Make sure that this * default router is only reachable thru this /* No change, do not do anything. */ logwarn(
"Cannot reach %s using %s\n",
/* Clear this default router. */ * Get IP address of default routers for each interface. * mib_item_t *item: the mib info buffer. * boolean_t *changed (referenced): set to B_TRUE if there is any change * -1 if there is no router found, 0 otherwise. /* NCA does not support IPv6... */ * Get Ethernet address for each default router from ARP. * mib_item_t *item: the mib info buffer. * boolean_t *changed (referenced): set to B_TRUE if there is any change * in ethernet address of router. * -1 if there is no ethernet address found, 0 otherwise. /* NCA does not support IPv6... */ * Ping all default routers. It just uses system(3F) to call * ping(1M) to do the job... * To get default router info (both IP address and ethernet address) for * each configured interface from IP. * boolean_t *changed (referenced): set to B_TRUE if there is any change * -1 if there is any error, 0 if everything is fine. logperror(
"cannot open ip to get router info");
* Ping every routers to make sure that ARP has all their ethernet * If the router IP address is not changed, its ethernet address * should not be changed. But just in case there is some IP * To remove the default router from an interface. * struct in_addr gw_addr: the IP address of the default router to be /* Search for the interface for this router. */ /* Clear the fields for this interface. */ * Wait for any changes in the routing table. If there are changes to * IP address or router ethernet address, send down the info to NCA. /* Loop forever waiting for any routing changes. */ logdebug(
"Waiting to read routing info...\n");
/* Don't die... Reinitialize socket and listen again. */ logdebug(
"Routing socket read error.\n");
" reinitializing routing" /* May be a transient error... */ /* Only handle default route deletion. */ "removal notice: gw %s\n",
/* May be a transient error... */ /* Nothing is changed, do nothing. */ "notice, but nothing is " * If name is NULL, it means that * we have encontered some problems * when configurating the interface. * So we remove it from the list. " configuration list.\n"),
" configuration list.\n"),
* This should not be possible * cleared already and this * function should not have /* Write directly to terminal, instead of syslog. */ /* Fork again so that we will never get a controlling terminal. */ /* Write directly to terminal, instead of syslog. */ " [interface1 interface2 ...]\n"),
argv[0]);
/* Don't run as daemon. */ /* -d and -c are "undocumented" options. */ " [interface1 interface2 ...]\n"),
argv[0]);
/* No network interface to proces... */ " [interface1 interface2 ...]\n"),
argv[0]);
/* Get IP address info for all the intefaces. */ " addresses for interfaces.\n");
/* No need to run as daemon if NCA is not making active connections. */ /* NCA does not support IPv6... */ * At boot up time, the default router may not have been * found. So ignore the error and check later. " information from network interface.\n");
/* Do the set up as daemon (if we are) to save time at boot up... */