17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*d04ccbb3Scarlsonj  * Common Development and Distribution License (the "License").
6*d04ccbb3Scarlsonj  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*d04ccbb3Scarlsonj  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #include "defs.h"
277c478bd9Sstevel@tonic-gate #include "tables.h"
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate /*
307c478bd9Sstevel@tonic-gate  * Parse the config file which consists of entries of the form:
317c478bd9Sstevel@tonic-gate  *	ifdefault	[<variable> <value>]*
327c478bd9Sstevel@tonic-gate  *	prefixdefault	[<variable> <value>]*
337c478bd9Sstevel@tonic-gate  *	if <ifname>	[<variable> <value>]*
347c478bd9Sstevel@tonic-gate  *	prefix <prefix>/<length> <ifname>	[<variable> <value>]*
357c478bd9Sstevel@tonic-gate  *
367c478bd9Sstevel@tonic-gate  * All "ifdefault" and "prefixdefault" entries must preceed any
377c478bd9Sstevel@tonic-gate  * "if" and "prefix" entries.
387c478bd9Sstevel@tonic-gate  *
397c478bd9Sstevel@tonic-gate  * Values (such as expiry dates) which contain white space
407c478bd9Sstevel@tonic-gate  * can be quoted with single or double quotes.
417c478bd9Sstevel@tonic-gate  */
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate /* maximum length of messages we send to syslog */
447c478bd9Sstevel@tonic-gate #define	NDPD_LOGMSGSIZE	1024
457c478bd9Sstevel@tonic-gate typedef	boolean_t	(*pfb_t)(char *, uint_t *);
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate struct configinfo {
487c478bd9Sstevel@tonic-gate 	char	*ci_name;
497c478bd9Sstevel@tonic-gate 	uint_t	ci_min;		/* 0: no min check */
507c478bd9Sstevel@tonic-gate 	uint_t	ci_max;		/* ~0U: no max check */
517c478bd9Sstevel@tonic-gate 	uint_t	ci_default;
527c478bd9Sstevel@tonic-gate 	uint_t	ci_index;	/* Into result array */
537c478bd9Sstevel@tonic-gate 	pfb_t	ci_parsefunc;	/* Parse function returns -1 on failure */
547c478bd9Sstevel@tonic-gate };
557c478bd9Sstevel@tonic-gate 
567c478bd9Sstevel@tonic-gate enum config_type { CONFIG_IF, CONFIG_PREFIX};
577c478bd9Sstevel@tonic-gate typedef enum config_type config_type_t;
587c478bd9Sstevel@tonic-gate 
597c478bd9Sstevel@tonic-gate static void set_protocol_defaults(void);
607c478bd9Sstevel@tonic-gate static void print_defaults(void);
617c478bd9Sstevel@tonic-gate static void parse_var_value(config_type_t, struct configinfo *, char *, char *,
627c478bd9Sstevel@tonic-gate     struct confvar *);
637c478bd9Sstevel@tonic-gate static void parse_default(config_type_t, struct configinfo *, char **, int,
647c478bd9Sstevel@tonic-gate     struct confvar *);
657c478bd9Sstevel@tonic-gate static void parse_if(struct configinfo *, char **, int);
667c478bd9Sstevel@tonic-gate static void parse_prefix(struct configinfo *, char **, int);
677c478bd9Sstevel@tonic-gate static boolean_t parse_onoff(char *, uint_t *);	/* boolean */
687c478bd9Sstevel@tonic-gate static boolean_t parse_int(char *, uint_t *);	/* integer */
697c478bd9Sstevel@tonic-gate static boolean_t parse_ms(char *, uint_t *);	/* milliseconds */
707c478bd9Sstevel@tonic-gate static boolean_t parse_s(char *, uint_t *);	/* seconds */
717c478bd9Sstevel@tonic-gate static boolean_t parse_date(char *, uint_t *);	/* date format */
727c478bd9Sstevel@tonic-gate static void conferr(char *fmt, ...);
737c478bd9Sstevel@tonic-gate static FILE *open_conffile(char *filename);
747c478bd9Sstevel@tonic-gate static int parse_line(char *line, char *argvec[], int argcount);
757c478bd9Sstevel@tonic-gate static int readline(FILE *fp, char *line, int length);
767c478bd9Sstevel@tonic-gate static int parse_addrprefix(char *strin, struct in6_addr *in6);
777c478bd9Sstevel@tonic-gate 
787c478bd9Sstevel@tonic-gate /*
797c478bd9Sstevel@tonic-gate  * Per interface configuration variables.
807c478bd9Sstevel@tonic-gate  * Min, max, and default values are from RFC 2461.
817c478bd9Sstevel@tonic-gate  */
827c478bd9Sstevel@tonic-gate static struct configinfo iflist[] = {
837c478bd9Sstevel@tonic-gate 	/* Name, Min, Max, Default, Index */
847c478bd9Sstevel@tonic-gate 	{ "DupAddrDetectTransmits", 0, 100, 1, I_DupAddrDetectTransmits,
857c478bd9Sstevel@tonic-gate 	parse_int },
867c478bd9Sstevel@tonic-gate 	{ "AdvSendAdvertisements", 0, 1, 0, I_AdvSendAdvertisements,
877c478bd9Sstevel@tonic-gate 	parse_onoff },
887c478bd9Sstevel@tonic-gate 	{ "MaxRtrAdvInterval", 4, 1800, 600, I_MaxRtrAdvInterval, parse_s },
897c478bd9Sstevel@tonic-gate 	{ "MinRtrAdvInterval", 3, 1350, 200, I_MinRtrAdvInterval, parse_s },
907c478bd9Sstevel@tonic-gate 	/*
917c478bd9Sstevel@tonic-gate 	 * No greater than .75 * MaxRtrAdvInterval.
927c478bd9Sstevel@tonic-gate 	 * Default: 0.33 * MaxRtrAdvInterval
937c478bd9Sstevel@tonic-gate 	 */
947c478bd9Sstevel@tonic-gate 	{ "AdvManagedFlag", 0, 1, 0, I_AdvManagedFlag, parse_onoff },
957c478bd9Sstevel@tonic-gate 	{ "AdvOtherConfigFlag", 0, 1, 0, I_AdvOtherConfigFlag, parse_onoff },
967c478bd9Sstevel@tonic-gate 	{ "AdvLinkMTU", IPV6_MIN_MTU, 65535, 0, I_AdvLinkMTU, parse_int },
977c478bd9Sstevel@tonic-gate 	{ "AdvReachableTime", 0, 3600000, 0, I_AdvReachableTime, parse_ms },
987c478bd9Sstevel@tonic-gate 	{ "AdvRetransTimer", 0, ~0U, 0, I_AdvRetransTimer, parse_ms },
997c478bd9Sstevel@tonic-gate 	{ "AdvCurHopLimit", 0, 255, 0, I_AdvCurHopLimit, parse_int },
1007c478bd9Sstevel@tonic-gate 	{ "AdvDefaultLifetime", 0, 9000, 1800, I_AdvDefaultLifetime, parse_s },
1017c478bd9Sstevel@tonic-gate 	/*
1027c478bd9Sstevel@tonic-gate 	 * MUST be either zero or between MaxRtrAdvInterval and 9000 seconds.
1037c478bd9Sstevel@tonic-gate 	 * Default: 3 * MaxRtrAdvInterval
1047c478bd9Sstevel@tonic-gate 	 */
1057c478bd9Sstevel@tonic-gate 	{ "StatelessAddrConf", 0, 1, 1, I_StatelessAddrConf, parse_onoff },
106*d04ccbb3Scarlsonj 	{ "StatefulAddrConf", 0, 1, 1, I_StatefulAddrConf, parse_onoff },
1077c478bd9Sstevel@tonic-gate 	/*
1087c478bd9Sstevel@tonic-gate 	 * Tmp* variables from RFC 3041, where defaults are defined.
1097c478bd9Sstevel@tonic-gate 	 */
1107c478bd9Sstevel@tonic-gate 	{ "TmpAddrsEnabled", 0, 1, 0, I_TmpAddrsEnabled, parse_onoff },
1117c478bd9Sstevel@tonic-gate 	{ "TmpValidLifetime", 0, ~0U, 604800, I_TmpValidLifetime, parse_s },
1127c478bd9Sstevel@tonic-gate 	{ "TmpPreferredLifetime", 0, ~0U, 86400, I_TmpPreferredLifetime,
1137c478bd9Sstevel@tonic-gate 	parse_s },
1147c478bd9Sstevel@tonic-gate 	{ "TmpRegenAdvance", 0, 60, 5, I_TmpRegenAdvance, parse_s },
1157c478bd9Sstevel@tonic-gate 	{ "TmpMaxDesyncFactor", 0, 600, 600, I_TmpMaxDesyncFactor, parse_s },
1167c478bd9Sstevel@tonic-gate 	{ NULL, 0, 0, 0, 0 }
1177c478bd9Sstevel@tonic-gate };
1187c478bd9Sstevel@tonic-gate 
1197c478bd9Sstevel@tonic-gate /*
1207c478bd9Sstevel@tonic-gate  * Per prefix: AdvPrefixList configuration variables.
1217c478bd9Sstevel@tonic-gate  * Min, max, and default values are from RFC 2461.
1227c478bd9Sstevel@tonic-gate  */
1237c478bd9Sstevel@tonic-gate static struct configinfo prefixlist[] = {
1247c478bd9Sstevel@tonic-gate 	/* Name, Min, Max, Default, Index */
1257c478bd9Sstevel@tonic-gate 	{ "AdvValidLifetime", 0, ~0U, 2592000, I_AdvValidLifetime,
1267c478bd9Sstevel@tonic-gate 	parse_s },
1277c478bd9Sstevel@tonic-gate 	{ "AdvOnLinkFlag", 0, 1, 1, I_AdvOnLinkFlag, parse_onoff },
1287c478bd9Sstevel@tonic-gate 	{ "AdvPreferredLifetime", 0, ~0U, 604800, I_AdvPreferredLifetime,
1297c478bd9Sstevel@tonic-gate 	parse_s},
1307c478bd9Sstevel@tonic-gate 	{ "AdvAutonomousFlag", 0, 1, 1, I_AdvAutonomousFlag, parse_onoff },
1317c478bd9Sstevel@tonic-gate 	{ "AdvValidExpiration", 0, ~0U, 0, I_AdvValidExpiration,
1327c478bd9Sstevel@tonic-gate 	parse_date },
1337c478bd9Sstevel@tonic-gate 	{ "AdvPreferredExpiration", 0, ~0U, 0, I_AdvPreferredExpiration,
1347c478bd9Sstevel@tonic-gate 	parse_date},
1357c478bd9Sstevel@tonic-gate 	{ NULL, 0, 0, 0, 0 },
1367c478bd9Sstevel@tonic-gate };
1377c478bd9Sstevel@tonic-gate 
1387c478bd9Sstevel@tonic-gate /*
1397c478bd9Sstevel@tonic-gate  * Data structures used to merge above protocol defaults
1407c478bd9Sstevel@tonic-gate  * with defaults specified in the configuration file.
1417c478bd9Sstevel@tonic-gate  * ifdefault is not static because new interfaces can be
1427c478bd9Sstevel@tonic-gate  * created outside of the configuration context.
1437c478bd9Sstevel@tonic-gate  */
1447c478bd9Sstevel@tonic-gate struct confvar ifdefaults[I_IFSIZE];
1457c478bd9Sstevel@tonic-gate static struct confvar prefixdefaults[I_PREFIXSIZE];
1467c478bd9Sstevel@tonic-gate 
1477c478bd9Sstevel@tonic-gate static char	conf_filename[MAXPATHLEN];
1487c478bd9Sstevel@tonic-gate static int	lineno;
1497c478bd9Sstevel@tonic-gate 
1507c478bd9Sstevel@tonic-gate /*
1517c478bd9Sstevel@tonic-gate  * Checks for violations of section 5.5.3 (c) of RFC 2462.
1527c478bd9Sstevel@tonic-gate  */
1537c478bd9Sstevel@tonic-gate static void
check_var_consistency(struct confvar * cv,void * save,int size)1547c478bd9Sstevel@tonic-gate check_var_consistency(struct confvar *cv, void *save, int size)
1557c478bd9Sstevel@tonic-gate {
1567c478bd9Sstevel@tonic-gate 	boolean_t rollback = _B_FALSE;
1577c478bd9Sstevel@tonic-gate 	int prefl, prefe, valid;
1587c478bd9Sstevel@tonic-gate 
1597c478bd9Sstevel@tonic-gate 	prefl = cv[I_AdvPreferredLifetime].cf_value;
1607c478bd9Sstevel@tonic-gate 	prefe = cv[I_AdvPreferredExpiration].cf_value;
1617c478bd9Sstevel@tonic-gate 	valid = cv[I_AdvValidLifetime].cf_value;
1627c478bd9Sstevel@tonic-gate 
1637c478bd9Sstevel@tonic-gate 	if (prefl > valid) {
1647c478bd9Sstevel@tonic-gate 		conferr("AdvPreferredLifetime (%u) is greater than "
1657c478bd9Sstevel@tonic-gate 		    "valid lifetime (%u)\n", prefl, valid);
1667c478bd9Sstevel@tonic-gate 		rollback = _B_TRUE;
1677c478bd9Sstevel@tonic-gate 	}
1687c478bd9Sstevel@tonic-gate 
1697c478bd9Sstevel@tonic-gate 	if (prefe > valid) {
1707c478bd9Sstevel@tonic-gate 		conferr("AdvPreferredExpiration (%u) is greater than "
1717c478bd9Sstevel@tonic-gate 		    "valid lifetime (%u)\n", prefe, valid);
1727c478bd9Sstevel@tonic-gate 		rollback = _B_TRUE;
1737c478bd9Sstevel@tonic-gate 	}
1747c478bd9Sstevel@tonic-gate 
1757c478bd9Sstevel@tonic-gate 	if (rollback) {
1767c478bd9Sstevel@tonic-gate 		(void) memcpy(cv, save, size);
1777c478bd9Sstevel@tonic-gate 	}
1787c478bd9Sstevel@tonic-gate }
1797c478bd9Sstevel@tonic-gate 
1807c478bd9Sstevel@tonic-gate /*
1817c478bd9Sstevel@tonic-gate  * Check for invalid lifetime values for RFC3041 addresses
1827c478bd9Sstevel@tonic-gate  */
1837c478bd9Sstevel@tonic-gate static void
check_if_var_consistency(struct confvar * cv,void * save,int size)1847c478bd9Sstevel@tonic-gate check_if_var_consistency(struct confvar *cv, void *save, int size)
1857c478bd9Sstevel@tonic-gate {
1867c478bd9Sstevel@tonic-gate 	boolean_t rollback = _B_FALSE;
1877c478bd9Sstevel@tonic-gate 	int tpref, tvalid, tdesync, tregen;
1887c478bd9Sstevel@tonic-gate 
1897c478bd9Sstevel@tonic-gate 	tpref = cv[I_TmpPreferredLifetime].cf_value;
1907c478bd9Sstevel@tonic-gate 	tvalid = cv[I_TmpValidLifetime].cf_value;
1917c478bd9Sstevel@tonic-gate 	tdesync = cv[I_TmpMaxDesyncFactor].cf_value;
1927c478bd9Sstevel@tonic-gate 	tregen = cv[I_TmpRegenAdvance].cf_value;
1937c478bd9Sstevel@tonic-gate 
1947c478bd9Sstevel@tonic-gate 	/*
1957c478bd9Sstevel@tonic-gate 	 * Only need to do this if tmp addrs are enabled.
1967c478bd9Sstevel@tonic-gate 	 */
1977c478bd9Sstevel@tonic-gate 	if (cv[I_TmpAddrsEnabled].cf_value == 0)
1987c478bd9Sstevel@tonic-gate 		return;
1997c478bd9Sstevel@tonic-gate 
2007c478bd9Sstevel@tonic-gate 	if (tdesync > tpref) {
2017c478bd9Sstevel@tonic-gate 		conferr("TmpDesyncFactor (%u) is greater than "
2027c478bd9Sstevel@tonic-gate 		    "TmpPreferredLifetime (%u)\n", tdesync, tpref);
2037c478bd9Sstevel@tonic-gate 		rollback = _B_TRUE;
2047c478bd9Sstevel@tonic-gate 	}
2057c478bd9Sstevel@tonic-gate 
2067c478bd9Sstevel@tonic-gate 	if (tpref > tvalid) {
2077c478bd9Sstevel@tonic-gate 		conferr("TmpPreferredLifetime (%u) is greater than "
2087c478bd9Sstevel@tonic-gate 		    "TmpValidLifetime (%u)\n", tpref, tvalid);
2097c478bd9Sstevel@tonic-gate 		rollback = _B_TRUE;
2107c478bd9Sstevel@tonic-gate 	}
2117c478bd9Sstevel@tonic-gate 
2127c478bd9Sstevel@tonic-gate 	if (tregen > tvalid) {
2137c478bd9Sstevel@tonic-gate 		conferr("TmpRegenAdvance (%u) is greater than "
2147c478bd9Sstevel@tonic-gate 		    "TmpValidLifetime (%u)\n", tregen, tvalid);
2157c478bd9Sstevel@tonic-gate 		rollback = _B_TRUE;
2167c478bd9Sstevel@tonic-gate 	}
2177c478bd9Sstevel@tonic-gate 
2187c478bd9Sstevel@tonic-gate 	if (rollback) {
2197c478bd9Sstevel@tonic-gate 		(void) memcpy(cv, save, size);
2207c478bd9Sstevel@tonic-gate 	}
2217c478bd9Sstevel@tonic-gate }
2227c478bd9Sstevel@tonic-gate 
2237c478bd9Sstevel@tonic-gate int
parse_config(char * config_file,boolean_t file_required)2247c478bd9Sstevel@tonic-gate parse_config(char *config_file, boolean_t file_required)
2257c478bd9Sstevel@tonic-gate {
2267c478bd9Sstevel@tonic-gate 	FILE *fp;
2277c478bd9Sstevel@tonic-gate 	char line[MAXLINELEN];
2287c478bd9Sstevel@tonic-gate 	char pline[MAXLINELEN];
2297c478bd9Sstevel@tonic-gate 	int argcount;
2307c478bd9Sstevel@tonic-gate 	char *argvec[MAXARGSPERLINE];
2317c478bd9Sstevel@tonic-gate 	int defaultdone = 0;	/* Set when first non-default command found */
2327c478bd9Sstevel@tonic-gate 
2337c478bd9Sstevel@tonic-gate 	if (debug & D_CONFIG)
2347c478bd9Sstevel@tonic-gate 		logmsg(LOG_DEBUG, "parse_config()\n");
2357c478bd9Sstevel@tonic-gate 
2367c478bd9Sstevel@tonic-gate 	set_protocol_defaults();
2377c478bd9Sstevel@tonic-gate 	if (debug & D_DEFAULTS)
2387c478bd9Sstevel@tonic-gate 		print_defaults();
2397c478bd9Sstevel@tonic-gate 
2407c478bd9Sstevel@tonic-gate 	fp = open_conffile(config_file);
2417c478bd9Sstevel@tonic-gate 	if (fp == NULL) {
2427c478bd9Sstevel@tonic-gate 		if (errno == ENOENT && !file_required)
2437c478bd9Sstevel@tonic-gate 			return (0);
2447c478bd9Sstevel@tonic-gate 		logperror(config_file);
2457c478bd9Sstevel@tonic-gate 		return (-1);
2467c478bd9Sstevel@tonic-gate 	}
2477c478bd9Sstevel@tonic-gate 	while (readline(fp, line, sizeof (line)) != 0) {
2487c478bd9Sstevel@tonic-gate 		(void) strncpy(pline, line, sizeof (pline));
2497c478bd9Sstevel@tonic-gate 		pline[sizeof (pline) - 1] = '\0';	/* NULL terminate */
2507c478bd9Sstevel@tonic-gate 		argcount = parse_line(pline, argvec,
2517c478bd9Sstevel@tonic-gate 		    sizeof (argvec) / sizeof (argvec[0]));
2527c478bd9Sstevel@tonic-gate 		if (debug & D_PARSE) {
2537c478bd9Sstevel@tonic-gate 			int i;
2547c478bd9Sstevel@tonic-gate 
2557c478bd9Sstevel@tonic-gate 			logmsg(LOG_DEBUG, "scanned %d args\n", argcount);
2567c478bd9Sstevel@tonic-gate 			for (i = 0; i < argcount; i++)
2577c478bd9Sstevel@tonic-gate 				logmsg(LOG_DEBUG, "arg[%d]: %s\n",
2587c478bd9Sstevel@tonic-gate 				    i, argvec[i]);
2597c478bd9Sstevel@tonic-gate 		}
2607c478bd9Sstevel@tonic-gate 		if (argcount == 0) {
2617c478bd9Sstevel@tonic-gate 			/* Empty line - or comment only line */
2627c478bd9Sstevel@tonic-gate 			continue;
2637c478bd9Sstevel@tonic-gate 		}
2647c478bd9Sstevel@tonic-gate 		if (strcmp(argvec[0], "ifdefault") == 0) {
2657c478bd9Sstevel@tonic-gate 			char save[sizeof (ifdefaults)];
2667c478bd9Sstevel@tonic-gate 
2677c478bd9Sstevel@tonic-gate 			if (defaultdone) {
2687c478bd9Sstevel@tonic-gate 				conferr("ifdefault after non-default "
2697c478bd9Sstevel@tonic-gate 				    "command\n");
2707c478bd9Sstevel@tonic-gate 				continue;
2717c478bd9Sstevel@tonic-gate 			}
2727c478bd9Sstevel@tonic-gate 			/*
2737c478bd9Sstevel@tonic-gate 			 * Save existing values in case what we read is
2747c478bd9Sstevel@tonic-gate 			 * invalid and we need to restore previous settings.
2757c478bd9Sstevel@tonic-gate 			 */
2767c478bd9Sstevel@tonic-gate 			(void) memcpy(save, ifdefaults, sizeof (ifdefaults));
2777c478bd9Sstevel@tonic-gate 			parse_default(CONFIG_IF, iflist, argvec+1, argcount-1,
2787c478bd9Sstevel@tonic-gate 			    ifdefaults);
2797c478bd9Sstevel@tonic-gate 			check_if_var_consistency(ifdefaults, save,
2807c478bd9Sstevel@tonic-gate 			    sizeof (save));
2817c478bd9Sstevel@tonic-gate 		} else if (strcmp(argvec[0], "prefixdefault") == 0) {
2827c478bd9Sstevel@tonic-gate 			char save[sizeof (prefixdefaults)];
2837c478bd9Sstevel@tonic-gate 
2847c478bd9Sstevel@tonic-gate 			if (defaultdone) {
2857c478bd9Sstevel@tonic-gate 				conferr("prefixdefault after non-default "
2867c478bd9Sstevel@tonic-gate 				    "command\n");
2877c478bd9Sstevel@tonic-gate 				continue;
2887c478bd9Sstevel@tonic-gate 			}
2897c478bd9Sstevel@tonic-gate 			/*
2907c478bd9Sstevel@tonic-gate 			 * Save existing values in case what we read is
2917c478bd9Sstevel@tonic-gate 			 * invalid and we need to restore previous settings.
2927c478bd9Sstevel@tonic-gate 			 */
2937c478bd9Sstevel@tonic-gate 			(void) memcpy(save, prefixdefaults,
2947c478bd9Sstevel@tonic-gate 			    sizeof (prefixdefaults));
2957c478bd9Sstevel@tonic-gate 			parse_default(CONFIG_PREFIX, prefixlist, argvec+1,
2967c478bd9Sstevel@tonic-gate 			    argcount-1, prefixdefaults);
2977c478bd9Sstevel@tonic-gate 			check_var_consistency(prefixdefaults, save,
2987c478bd9Sstevel@tonic-gate 			    sizeof (save));
2997c478bd9Sstevel@tonic-gate 		} else if (strcmp(argvec[0], "if") == 0) {
3007c478bd9Sstevel@tonic-gate 			defaultdone = 1;
3017c478bd9Sstevel@tonic-gate 			parse_if(iflist, argvec+1, argcount-1);
3027c478bd9Sstevel@tonic-gate 		} else if (strcmp(argvec[0], "prefix") == 0) {
3037c478bd9Sstevel@tonic-gate 			defaultdone = 1;
3047c478bd9Sstevel@tonic-gate 			parse_prefix(prefixlist, argvec+1, argcount-1);
3057c478bd9Sstevel@tonic-gate 		} else {
3067c478bd9Sstevel@tonic-gate 			conferr("Unknown command: %s\n", argvec[0]);
3077c478bd9Sstevel@tonic-gate 		}
3087c478bd9Sstevel@tonic-gate 	}
3097c478bd9Sstevel@tonic-gate 	(void) fclose(fp);
3107c478bd9Sstevel@tonic-gate 	if (debug & D_DEFAULTS)
3117c478bd9Sstevel@tonic-gate 		print_defaults();
3127c478bd9Sstevel@tonic-gate 	return (0);
3137c478bd9Sstevel@tonic-gate }
3147c478bd9Sstevel@tonic-gate 
3157c478bd9Sstevel@tonic-gate /*
3167c478bd9Sstevel@tonic-gate  * Extract the defaults from the configinfo tables to initialize
3177c478bd9Sstevel@tonic-gate  * the ifdefaults and prefixdefaults arrays.
3187c478bd9Sstevel@tonic-gate  * The arrays are needed to track which defaults have been changed
3197c478bd9Sstevel@tonic-gate  * by the config file.
3207c478bd9Sstevel@tonic-gate  */
3217c478bd9Sstevel@tonic-gate static void
set_protocol_defaults(void)3227c478bd9Sstevel@tonic-gate set_protocol_defaults(void)
3237c478bd9Sstevel@tonic-gate {
3247c478bd9Sstevel@tonic-gate 	struct configinfo *cip;
3257c478bd9Sstevel@tonic-gate 
3267c478bd9Sstevel@tonic-gate 	if (debug & D_DEFAULTS)
3277c478bd9Sstevel@tonic-gate 		logmsg(LOG_DEBUG, "extract_protocol_defaults\n");
3287c478bd9Sstevel@tonic-gate 	for (cip = iflist; cip->ci_name != NULL; cip++) {
3297c478bd9Sstevel@tonic-gate 		ifdefaults[cip->ci_index].cf_value = cip->ci_default;
3307c478bd9Sstevel@tonic-gate 		ifdefaults[cip->ci_index].cf_notdefault = _B_FALSE;
3317c478bd9Sstevel@tonic-gate 	}
3327c478bd9Sstevel@tonic-gate 	for (cip = prefixlist; cip->ci_name != NULL; cip++) {
3337c478bd9Sstevel@tonic-gate 		prefixdefaults[cip->ci_index].cf_value = cip->ci_default;
3347c478bd9Sstevel@tonic-gate 		prefixdefaults[cip->ci_index].cf_notdefault = _B_FALSE;
3357c478bd9Sstevel@tonic-gate 	}
3367c478bd9Sstevel@tonic-gate }
3377c478bd9Sstevel@tonic-gate 
3387c478bd9Sstevel@tonic-gate void
print_iflist(struct confvar * confvar)3397c478bd9Sstevel@tonic-gate print_iflist(struct confvar *confvar)
3407c478bd9Sstevel@tonic-gate {
3417c478bd9Sstevel@tonic-gate 	struct configinfo *cip;
3427c478bd9Sstevel@tonic-gate 
3437c478bd9Sstevel@tonic-gate 	for (cip = iflist; cip->ci_name != NULL; cip++) {
3447c478bd9Sstevel@tonic-gate 		logmsg(LOG_DEBUG, "\t%s min %u max %u def %u value %u set %d\n",
3457c478bd9Sstevel@tonic-gate 		    cip->ci_name, cip->ci_min, cip->ci_max, cip->ci_default,
3467c478bd9Sstevel@tonic-gate 		    confvar[cip->ci_index].cf_value,
3477c478bd9Sstevel@tonic-gate 		    confvar[cip->ci_index].cf_notdefault);
3487c478bd9Sstevel@tonic-gate 	}
3497c478bd9Sstevel@tonic-gate }
3507c478bd9Sstevel@tonic-gate 
3517c478bd9Sstevel@tonic-gate void
print_prefixlist(struct confvar * confvar)3527c478bd9Sstevel@tonic-gate print_prefixlist(struct confvar *confvar)
3537c478bd9Sstevel@tonic-gate {
3547c478bd9Sstevel@tonic-gate 	struct configinfo *cip;
3557c478bd9Sstevel@tonic-gate 
3567c478bd9Sstevel@tonic-gate 	for (cip = prefixlist; cip->ci_name != NULL; cip++) {
3577c478bd9Sstevel@tonic-gate 		logmsg(LOG_DEBUG, "\t%s min %u max %u def %u value %u set %d\n",
3587c478bd9Sstevel@tonic-gate 		    cip->ci_name, cip->ci_min, cip->ci_max, cip->ci_default,
3597c478bd9Sstevel@tonic-gate 		    confvar[cip->ci_index].cf_value,
3607c478bd9Sstevel@tonic-gate 		    confvar[cip->ci_index].cf_notdefault);
3617c478bd9Sstevel@tonic-gate 	}
3627c478bd9Sstevel@tonic-gate }
3637c478bd9Sstevel@tonic-gate 
3647c478bd9Sstevel@tonic-gate 
3657c478bd9Sstevel@tonic-gate static void
print_defaults(void)3667c478bd9Sstevel@tonic-gate print_defaults(void)
3677c478bd9Sstevel@tonic-gate {
3687c478bd9Sstevel@tonic-gate 	logmsg(LOG_DEBUG, "Default interface variables:\n");
3697c478bd9Sstevel@tonic-gate 	print_iflist(ifdefaults);
3707c478bd9Sstevel@tonic-gate 	logmsg(LOG_DEBUG, "Default prefix variables:\n");
3717c478bd9Sstevel@tonic-gate 	print_prefixlist(prefixdefaults);
3727c478bd9Sstevel@tonic-gate }
3737c478bd9Sstevel@tonic-gate 
3747c478bd9Sstevel@tonic-gate /*
3757c478bd9Sstevel@tonic-gate  * Read from fp. Handle \ at the end of the line by joining lines together.
3767c478bd9Sstevel@tonic-gate  * Return 0 on EOF.
3777c478bd9Sstevel@tonic-gate  */
3787c478bd9Sstevel@tonic-gate static int
readline(FILE * fp,char * line,int length)3797c478bd9Sstevel@tonic-gate readline(FILE *fp, char *line, int length)
3807c478bd9Sstevel@tonic-gate {
3817c478bd9Sstevel@tonic-gate 	int got = 0;
3827c478bd9Sstevel@tonic-gate 
3837c478bd9Sstevel@tonic-gate retry:
3847c478bd9Sstevel@tonic-gate 	errno = 0;
3857c478bd9Sstevel@tonic-gate 	if (fgets(line, length, fp) == NULL) {
3867c478bd9Sstevel@tonic-gate 		if (errno == EINTR)
3877c478bd9Sstevel@tonic-gate 			goto retry;
3887c478bd9Sstevel@tonic-gate 		if (got != 0)
3897c478bd9Sstevel@tonic-gate 			return (1);
3907c478bd9Sstevel@tonic-gate 		else
3917c478bd9Sstevel@tonic-gate 			return (0);
3927c478bd9Sstevel@tonic-gate 	}
3937c478bd9Sstevel@tonic-gate 	lineno++;
3947c478bd9Sstevel@tonic-gate 	got = strlen(line);
3957c478bd9Sstevel@tonic-gate 	/* Look for trailing \. Note that fgets includes the linefeed. */
3967c478bd9Sstevel@tonic-gate 	if (got >= 2 && line[got-2] == '\\') {
3977c478bd9Sstevel@tonic-gate 		/* Skip \ and LF */
3987c478bd9Sstevel@tonic-gate 		line += got - 2;
3997c478bd9Sstevel@tonic-gate 		length -= got - 2;
4007c478bd9Sstevel@tonic-gate 		goto retry;
4017c478bd9Sstevel@tonic-gate 	}
4027c478bd9Sstevel@tonic-gate 	/* Remove the trailing linefeed */
4037c478bd9Sstevel@tonic-gate 	if (got > 0)
4047c478bd9Sstevel@tonic-gate 		line[got-1] = '\0';
4057c478bd9Sstevel@tonic-gate 
4067c478bd9Sstevel@tonic-gate 	return (1);
4077c478bd9Sstevel@tonic-gate }
4087c478bd9Sstevel@tonic-gate 
4097c478bd9Sstevel@tonic-gate /*
4107c478bd9Sstevel@tonic-gate  * Parse a line splitting it off at whitspace characters.
4117c478bd9Sstevel@tonic-gate  * Modifies the content of the string by inserting NULLs.
4127c478bd9Sstevel@tonic-gate  * If more arguments than fits in argvec/argcount then ignore the last.
4137c478bd9Sstevel@tonic-gate  * Returns argcount.
4147c478bd9Sstevel@tonic-gate  * Handles single quotes and double quotes.
4157c478bd9Sstevel@tonic-gate  */
4167c478bd9Sstevel@tonic-gate static int
parse_line(char * line,char * argvec[],int argcount)4177c478bd9Sstevel@tonic-gate parse_line(char *line, char *argvec[], int argcount)
4187c478bd9Sstevel@tonic-gate {
4197c478bd9Sstevel@tonic-gate 	int i = 0;
4207c478bd9Sstevel@tonic-gate 	char *cp;
4217c478bd9Sstevel@tonic-gate 	boolean_t insingle_quote = _B_FALSE;
4227c478bd9Sstevel@tonic-gate 	boolean_t indouble_quote = _B_FALSE;
4237c478bd9Sstevel@tonic-gate 
4247c478bd9Sstevel@tonic-gate 	/* Truncate at the beginning of a comment */
4257c478bd9Sstevel@tonic-gate 	cp = strchr(line, '#');
4267c478bd9Sstevel@tonic-gate 	if (cp != NULL)
4277c478bd9Sstevel@tonic-gate 		*cp = '\0';
4287c478bd9Sstevel@tonic-gate 
4297c478bd9Sstevel@tonic-gate 	for (;;) {
4307c478bd9Sstevel@tonic-gate 		/* Skip any whitespace */
4317c478bd9Sstevel@tonic-gate 		while (isspace(*line) && *line != '\0')
4327c478bd9Sstevel@tonic-gate 			line++;
4337c478bd9Sstevel@tonic-gate 
4347c478bd9Sstevel@tonic-gate 		if (*line == '\'') {
4357c478bd9Sstevel@tonic-gate 			line++;
4367c478bd9Sstevel@tonic-gate 			if (*line == '\0')
4377c478bd9Sstevel@tonic-gate 				return (i);
4387c478bd9Sstevel@tonic-gate 			insingle_quote = _B_TRUE;
4397c478bd9Sstevel@tonic-gate 		} else if (*line == '"') {
4407c478bd9Sstevel@tonic-gate 			line++;
4417c478bd9Sstevel@tonic-gate 			if (*line == '\0')
4427c478bd9Sstevel@tonic-gate 				return (i);
4437c478bd9Sstevel@tonic-gate 			indouble_quote = _B_TRUE;
4447c478bd9Sstevel@tonic-gate 		}
4457c478bd9Sstevel@tonic-gate 		argvec[i] = line;
4467c478bd9Sstevel@tonic-gate 		if (*line == '\0')
4477c478bd9Sstevel@tonic-gate 			return (i);
4487c478bd9Sstevel@tonic-gate 		i++;
4497c478bd9Sstevel@tonic-gate 		/* Skip until next whitespace or end of quoted text */
4507c478bd9Sstevel@tonic-gate 		if (insingle_quote) {
4517c478bd9Sstevel@tonic-gate 			while (*line != '\'' && *line != '\0')
4527c478bd9Sstevel@tonic-gate 				line++;
4537c478bd9Sstevel@tonic-gate 			if (*line == '\'') {
4547c478bd9Sstevel@tonic-gate 				*line = ' ';
4557c478bd9Sstevel@tonic-gate 			} else {
4567c478bd9Sstevel@tonic-gate 				/* Handle missing quote at end */
4577c478bd9Sstevel@tonic-gate 				i--;
4587c478bd9Sstevel@tonic-gate 				conferr("Missing end quote - ignoring <%s>\n",
4597c478bd9Sstevel@tonic-gate 				    argvec[i]);
4607c478bd9Sstevel@tonic-gate 				return (i);
4617c478bd9Sstevel@tonic-gate 			}
4627c478bd9Sstevel@tonic-gate 			insingle_quote = _B_FALSE;
4637c478bd9Sstevel@tonic-gate 		} else if (indouble_quote) {
4647c478bd9Sstevel@tonic-gate 			while (*line != '"' && *line != '\0')
4657c478bd9Sstevel@tonic-gate 				line++;
4667c478bd9Sstevel@tonic-gate 			if (*line == '"') {
4677c478bd9Sstevel@tonic-gate 				*line = ' ';
4687c478bd9Sstevel@tonic-gate 			} else {
4697c478bd9Sstevel@tonic-gate 				/* Handle missing quote at end */
4707c478bd9Sstevel@tonic-gate 				i--;
4717c478bd9Sstevel@tonic-gate 				conferr("Missing end quote - ignoring <%s>\n",
4727c478bd9Sstevel@tonic-gate 				    argvec[i]);
4737c478bd9Sstevel@tonic-gate 				return (i);
4747c478bd9Sstevel@tonic-gate 			}
4757c478bd9Sstevel@tonic-gate 			indouble_quote = _B_FALSE;
4767c478bd9Sstevel@tonic-gate 		} else {
4777c478bd9Sstevel@tonic-gate 			while (!isspace(*line) && *line != '\0')
4787c478bd9Sstevel@tonic-gate 				line++;
4797c478bd9Sstevel@tonic-gate 		}
4807c478bd9Sstevel@tonic-gate 		if (*line != '\0') {
4817c478bd9Sstevel@tonic-gate 			/* Break off argument */
4827c478bd9Sstevel@tonic-gate 			*line++ = '\0';
4837c478bd9Sstevel@tonic-gate 		}
4847c478bd9Sstevel@tonic-gate 		if (i > argcount)
4857c478bd9Sstevel@tonic-gate 			return (argcount);
4867c478bd9Sstevel@tonic-gate 	}
4877c478bd9Sstevel@tonic-gate 	/* NOTREACHED */
4887c478bd9Sstevel@tonic-gate }
4897c478bd9Sstevel@tonic-gate 
4907c478bd9Sstevel@tonic-gate static void
parse_var_value(config_type_t type,struct configinfo * list,char * varstr,char * valstr,struct confvar * confvar)4917c478bd9Sstevel@tonic-gate parse_var_value(config_type_t type, struct configinfo *list, char *varstr,
4927c478bd9Sstevel@tonic-gate     char *valstr, struct confvar *confvar)
4937c478bd9Sstevel@tonic-gate {
4947c478bd9Sstevel@tonic-gate 	struct configinfo *cip;
4957c478bd9Sstevel@tonic-gate 	uint_t val;
4967c478bd9Sstevel@tonic-gate 
4977c478bd9Sstevel@tonic-gate 	if (debug & D_CONFIG) {
4987c478bd9Sstevel@tonic-gate 		logmsg(LOG_DEBUG, "parse_var_value(%d, %s, %s)\n",
4997c478bd9Sstevel@tonic-gate 		    (int)type, varstr, valstr);
5007c478bd9Sstevel@tonic-gate 	}
5017c478bd9Sstevel@tonic-gate 
5027c478bd9Sstevel@tonic-gate 	for (cip = list; cip->ci_name != NULL; cip++) {
5037c478bd9Sstevel@tonic-gate 		if (strcasecmp(cip->ci_name, varstr) == 0)
5047c478bd9Sstevel@tonic-gate 			break;
5057c478bd9Sstevel@tonic-gate 	}
5067c478bd9Sstevel@tonic-gate 	if (cip->ci_name == NULL) {
5077c478bd9Sstevel@tonic-gate 		conferr("Unknown variable: <%s>\n", varstr);
5087c478bd9Sstevel@tonic-gate 		return;
5097c478bd9Sstevel@tonic-gate 	}
5107c478bd9Sstevel@tonic-gate 	if (!(*cip->ci_parsefunc)(valstr, &val)) {
5117c478bd9Sstevel@tonic-gate 		conferr("Bad value: <%s>\n", valstr);
5127c478bd9Sstevel@tonic-gate 		return;
5137c478bd9Sstevel@tonic-gate 	}
5147c478bd9Sstevel@tonic-gate 	if (cip->ci_min != 0 && val < cip->ci_min) {
5157c478bd9Sstevel@tonic-gate 		conferr("Value %s is below minimum %u for %s\n",
5167c478bd9Sstevel@tonic-gate 		    valstr, cip->ci_min, varstr);
5177c478bd9Sstevel@tonic-gate 		return;
5187c478bd9Sstevel@tonic-gate 	}
5197c478bd9Sstevel@tonic-gate 	if (cip->ci_max != ~0U && val > cip->ci_max) {
5207c478bd9Sstevel@tonic-gate 		conferr("Value %s is above maximum %u for %s\n",
5217c478bd9Sstevel@tonic-gate 		    valstr, cip->ci_max, varstr);
5227c478bd9Sstevel@tonic-gate 		return;
5237c478bd9Sstevel@tonic-gate 	}
5247c478bd9Sstevel@tonic-gate 	/* Check against dynamic/relative limits */
5257c478bd9Sstevel@tonic-gate 	if (type == CONFIG_IF) {
5267c478bd9Sstevel@tonic-gate 		if (cip->ci_index == I_MinRtrAdvInterval &&
5277c478bd9Sstevel@tonic-gate 		    confvar[I_MaxRtrAdvInterval].cf_notdefault &&
5287c478bd9Sstevel@tonic-gate 		    val > confvar[I_MaxRtrAdvInterval].cf_value * 0.75) {
5297c478bd9Sstevel@tonic-gate 			conferr("MinRtrAdvInterval exceeds .75 * "
5307c478bd9Sstevel@tonic-gate 			    "MaxRtrAdvInterval (%u)\n",
5317c478bd9Sstevel@tonic-gate 			    confvar[I_MaxRtrAdvInterval].cf_value);
5327c478bd9Sstevel@tonic-gate 			return;
5337c478bd9Sstevel@tonic-gate 		}
5347c478bd9Sstevel@tonic-gate 		if (cip->ci_index == I_MaxRtrAdvInterval &&
5357c478bd9Sstevel@tonic-gate 		    confvar[I_MinRtrAdvInterval].cf_notdefault &&
5367c478bd9Sstevel@tonic-gate 		    confvar[I_MinRtrAdvInterval].cf_value > val * 0.75) {
5377c478bd9Sstevel@tonic-gate 			conferr("MinRtrAdvInterval (%u) exceeds .75 * "
5387c478bd9Sstevel@tonic-gate 			    "MaxRtrAdvInterval\n",
5397c478bd9Sstevel@tonic-gate 			    confvar[I_MinRtrAdvInterval].cf_value);
5407c478bd9Sstevel@tonic-gate 			return;
5417c478bd9Sstevel@tonic-gate 		}
5427c478bd9Sstevel@tonic-gate 		if (cip->ci_index == I_AdvDefaultLifetime &&
5437c478bd9Sstevel@tonic-gate 		    confvar[I_MaxRtrAdvInterval].cf_notdefault &&
5447c478bd9Sstevel@tonic-gate 		    val != 0 &&
5457c478bd9Sstevel@tonic-gate 		    val < confvar[I_MaxRtrAdvInterval].cf_value) {
5467c478bd9Sstevel@tonic-gate 			conferr("AdvDefaultLifetime is not between "
5477c478bd9Sstevel@tonic-gate 			    "MaxRtrAdrInterval (%u) and 9000 seconds\n",
5487c478bd9Sstevel@tonic-gate 			    confvar[I_MaxRtrAdvInterval].cf_value);
5497c478bd9Sstevel@tonic-gate 			return;
5507c478bd9Sstevel@tonic-gate 		}
5517c478bd9Sstevel@tonic-gate 		if (cip->ci_index == I_MaxRtrAdvInterval &&
5527c478bd9Sstevel@tonic-gate 		    confvar[I_AdvDefaultLifetime].cf_notdefault &&
5537c478bd9Sstevel@tonic-gate 		    confvar[I_AdvDefaultLifetime].cf_value < val) {
5547c478bd9Sstevel@tonic-gate 			conferr("AdvDefaultLifetime (%u) is not between "
5557c478bd9Sstevel@tonic-gate 			    "MaxRtrAdrInterval and 9000 seconds\n",
5567c478bd9Sstevel@tonic-gate 			    confvar[I_AdvDefaultLifetime].cf_value);
5577c478bd9Sstevel@tonic-gate 			return;
5587c478bd9Sstevel@tonic-gate 		}
5597c478bd9Sstevel@tonic-gate 	}
5607c478bd9Sstevel@tonic-gate 	confvar[cip->ci_index].cf_value = val;
5617c478bd9Sstevel@tonic-gate 	confvar[cip->ci_index].cf_notdefault = _B_TRUE;
5627c478bd9Sstevel@tonic-gate 
5637c478bd9Sstevel@tonic-gate 	/* Derive dynamic/relative variables based on this one */
5647c478bd9Sstevel@tonic-gate 	if (type == CONFIG_IF) {
5657c478bd9Sstevel@tonic-gate 		if (cip->ci_index == I_MaxRtrAdvInterval &&
5667c478bd9Sstevel@tonic-gate 		    !confvar[I_MinRtrAdvInterval].cf_notdefault)
5677c478bd9Sstevel@tonic-gate 			confvar[I_MinRtrAdvInterval].cf_value = val / 3;
5687c478bd9Sstevel@tonic-gate 		if (cip->ci_index == I_MaxRtrAdvInterval &&
5697c478bd9Sstevel@tonic-gate 		    !confvar[I_AdvDefaultLifetime].cf_notdefault)
5707c478bd9Sstevel@tonic-gate 		    confvar[I_AdvDefaultLifetime].cf_value = 3 * val;
5717c478bd9Sstevel@tonic-gate 	}
5727c478bd9Sstevel@tonic-gate }
5737c478bd9Sstevel@tonic-gate 
5747c478bd9Sstevel@tonic-gate /*
5757c478bd9Sstevel@tonic-gate  * Split up the line into <variable> <value> pairs
5767c478bd9Sstevel@tonic-gate  */
5777c478bd9Sstevel@tonic-gate static void
parse_default(config_type_t type,struct configinfo * list,char * argvec[],int argcount,struct confvar * defaults)5787c478bd9Sstevel@tonic-gate parse_default(config_type_t type, struct configinfo *list,
5797c478bd9Sstevel@tonic-gate     char *argvec[], int argcount, struct confvar *defaults)
5807c478bd9Sstevel@tonic-gate {
5817c478bd9Sstevel@tonic-gate 	if (debug & D_CONFIG)
5827c478bd9Sstevel@tonic-gate 		logmsg(LOG_DEBUG, "parse_default: argc %d\n", argcount);
5837c478bd9Sstevel@tonic-gate 	while (argcount >= 2) {
5847c478bd9Sstevel@tonic-gate 		parse_var_value(type, list, argvec[0], argvec[1], defaults);
5857c478bd9Sstevel@tonic-gate 
5867c478bd9Sstevel@tonic-gate 		argcount -= 2;
5877c478bd9Sstevel@tonic-gate 		argvec += 2;
5887c478bd9Sstevel@tonic-gate 	}
5897c478bd9Sstevel@tonic-gate 	if (argcount != 0)
5907c478bd9Sstevel@tonic-gate 		conferr("Trailing text <%s> ignored\n", argvec[0]);
5917c478bd9Sstevel@tonic-gate }
5927c478bd9Sstevel@tonic-gate 
5937c478bd9Sstevel@tonic-gate /*
5947c478bd9Sstevel@tonic-gate  * Returns true if ok; otherwise false.
5957c478bd9Sstevel@tonic-gate  */
5967c478bd9Sstevel@tonic-gate static void
parse_if(struct configinfo * list,char * argvec[],int argcount)5977c478bd9Sstevel@tonic-gate parse_if(struct configinfo *list, char *argvec[], int argcount)
5987c478bd9Sstevel@tonic-gate {
5997c478bd9Sstevel@tonic-gate 	char *ifname;
6007c478bd9Sstevel@tonic-gate 	struct phyint *pi;
6017c478bd9Sstevel@tonic-gate 	char save[sizeof (pi->pi_config)];
6027c478bd9Sstevel@tonic-gate 
6037c478bd9Sstevel@tonic-gate 	if (debug & D_CONFIG)
6047c478bd9Sstevel@tonic-gate 		logmsg(LOG_DEBUG, "parse_if: argc %d\n", argcount);
6057c478bd9Sstevel@tonic-gate 
6067c478bd9Sstevel@tonic-gate 	if (argcount < 1) {
6077c478bd9Sstevel@tonic-gate 		conferr("Missing interface name\n");
6087c478bd9Sstevel@tonic-gate 		return;
6097c478bd9Sstevel@tonic-gate 	}
6107c478bd9Sstevel@tonic-gate 	ifname = argvec[0];
6117c478bd9Sstevel@tonic-gate 	argvec++;
6127c478bd9Sstevel@tonic-gate 	argcount--;
6137c478bd9Sstevel@tonic-gate 
6147c478bd9Sstevel@tonic-gate 	pi = phyint_lookup(ifname);
6157c478bd9Sstevel@tonic-gate 	if (pi == NULL) {
6167c478bd9Sstevel@tonic-gate 		/*
6177c478bd9Sstevel@tonic-gate 		 * Create the physical interface structure.
6187c478bd9Sstevel@tonic-gate 		 * Note, phyint_create() sets the interface
6197c478bd9Sstevel@tonic-gate 		 * defaults in pi_config.
6207c478bd9Sstevel@tonic-gate 		 */
6217c478bd9Sstevel@tonic-gate 		pi = phyint_create(ifname);
6227c478bd9Sstevel@tonic-gate 		if (pi == NULL) {
6237c478bd9Sstevel@tonic-gate 			conferr("Unable to use interface %s\n", ifname);
6247c478bd9Sstevel@tonic-gate 			return;
6257c478bd9Sstevel@tonic-gate 		}
6267c478bd9Sstevel@tonic-gate 	}
6277c478bd9Sstevel@tonic-gate 
6287c478bd9Sstevel@tonic-gate 	(void) memcpy(save, pi->pi_config, sizeof (save));
6297c478bd9Sstevel@tonic-gate 	while (argcount >= 2) {
6307c478bd9Sstevel@tonic-gate 		parse_var_value(CONFIG_IF, list, argvec[0], argvec[1],
6317c478bd9Sstevel@tonic-gate 		    pi->pi_config);
6327c478bd9Sstevel@tonic-gate 
6337c478bd9Sstevel@tonic-gate 		argcount -= 2;
6347c478bd9Sstevel@tonic-gate 		argvec += 2;
6357c478bd9Sstevel@tonic-gate 	}
6367c478bd9Sstevel@tonic-gate 	if (argcount != 0)
6377c478bd9Sstevel@tonic-gate 		logmsg(LOG_ERR, "Trailing text <%s> ignored\n", argvec[0]);
6387c478bd9Sstevel@tonic-gate 	check_if_var_consistency(pi->pi_config, save, sizeof (save));
6397c478bd9Sstevel@tonic-gate }
6407c478bd9Sstevel@tonic-gate 
6417c478bd9Sstevel@tonic-gate static void
parse_prefix(struct configinfo * list,char * argvec[],int argcount)6427c478bd9Sstevel@tonic-gate parse_prefix(struct configinfo *list, char *argvec[], int argcount)
6437c478bd9Sstevel@tonic-gate {
6447c478bd9Sstevel@tonic-gate 	char *ifname, *prefix;
6457c478bd9Sstevel@tonic-gate 	struct phyint *pi;
6467c478bd9Sstevel@tonic-gate 	struct adv_prefix *adv_pr;
6477c478bd9Sstevel@tonic-gate 	struct in6_addr in6;
6487c478bd9Sstevel@tonic-gate 	int prefixlen;
6497c478bd9Sstevel@tonic-gate 	char save[sizeof (adv_pr->adv_pr_config)];
6507c478bd9Sstevel@tonic-gate 
6517c478bd9Sstevel@tonic-gate 	if (debug & D_CONFIG)
6527c478bd9Sstevel@tonic-gate 		logmsg(LOG_DEBUG, "parse_prefix: argc %d\n", argcount);
6537c478bd9Sstevel@tonic-gate 
6547c478bd9Sstevel@tonic-gate 	if (argcount < 2) {
6557c478bd9Sstevel@tonic-gate 		conferr("Missing prefix and/or interface name\n");
6567c478bd9Sstevel@tonic-gate 		return;
6577c478bd9Sstevel@tonic-gate 	}
6587c478bd9Sstevel@tonic-gate 	prefix = argvec[0];
6597c478bd9Sstevel@tonic-gate 	ifname = argvec[1];
6607c478bd9Sstevel@tonic-gate 	argvec += 2;
6617c478bd9Sstevel@tonic-gate 	argcount -= 2;
6627c478bd9Sstevel@tonic-gate 
6637c478bd9Sstevel@tonic-gate 	prefixlen = parse_addrprefix(prefix, &in6);
6647c478bd9Sstevel@tonic-gate 	if (prefixlen == -1) {
6657c478bd9Sstevel@tonic-gate 		conferr("Bad prefix %s\n", prefix);
6667c478bd9Sstevel@tonic-gate 		return;
6677c478bd9Sstevel@tonic-gate 	}
6687c478bd9Sstevel@tonic-gate 
6697c478bd9Sstevel@tonic-gate 	pi = phyint_lookup(ifname);
6707c478bd9Sstevel@tonic-gate 	if (pi == NULL) {
6717c478bd9Sstevel@tonic-gate 		/*
6727c478bd9Sstevel@tonic-gate 		 * Create the physical interface structure.
6737c478bd9Sstevel@tonic-gate 		 * Note, phyint_create() sets the interface
6747c478bd9Sstevel@tonic-gate 		 * defaults in pi_config.
6757c478bd9Sstevel@tonic-gate 		 */
6767c478bd9Sstevel@tonic-gate 		pi = phyint_create(ifname);
6777c478bd9Sstevel@tonic-gate 		if (pi == NULL) {
6787c478bd9Sstevel@tonic-gate 			conferr("Unable to use interface %s\n", ifname);
6797c478bd9Sstevel@tonic-gate 			return;
6807c478bd9Sstevel@tonic-gate 		}
6817c478bd9Sstevel@tonic-gate 	}
6827c478bd9Sstevel@tonic-gate 	adv_pr = adv_prefix_lookup(pi, in6, prefixlen);
6837c478bd9Sstevel@tonic-gate 	if (adv_pr == NULL) {
6847c478bd9Sstevel@tonic-gate 		int i;
6857c478bd9Sstevel@tonic-gate 
6867c478bd9Sstevel@tonic-gate 		adv_pr = adv_prefix_create(pi, in6, prefixlen);
6877c478bd9Sstevel@tonic-gate 		if (adv_pr == NULL) {
6887c478bd9Sstevel@tonic-gate 			conferr("Unable to create prefix %s\n", prefix);
6897c478bd9Sstevel@tonic-gate 			return;
6907c478bd9Sstevel@tonic-gate 		}
6917c478bd9Sstevel@tonic-gate 		/*
6927c478bd9Sstevel@tonic-gate 		 * Copy the defaults from the default array.
6937c478bd9Sstevel@tonic-gate 		 */
6947c478bd9Sstevel@tonic-gate 		for (i = 0; i < I_PREFIXSIZE; i++) {
6957c478bd9Sstevel@tonic-gate 			adv_pr->adv_pr_config[i].cf_value =
6967c478bd9Sstevel@tonic-gate 			    prefixdefaults[i].cf_value;
6977c478bd9Sstevel@tonic-gate 			adv_pr->adv_pr_config[i].cf_notdefault =
6987c478bd9Sstevel@tonic-gate 			    prefixdefaults[i].cf_notdefault;
6997c478bd9Sstevel@tonic-gate 		}
7007c478bd9Sstevel@tonic-gate 	}
7017c478bd9Sstevel@tonic-gate 
7027c478bd9Sstevel@tonic-gate 	(void) memcpy(save, adv_pr->adv_pr_config, sizeof (save));
7037c478bd9Sstevel@tonic-gate 	while (argcount >= 2) {
7047c478bd9Sstevel@tonic-gate 		parse_var_value(CONFIG_PREFIX, list, argvec[0], argvec[1],
7057c478bd9Sstevel@tonic-gate 		    adv_pr->adv_pr_config);
7067c478bd9Sstevel@tonic-gate 
7077c478bd9Sstevel@tonic-gate 		argcount -= 2;
7087c478bd9Sstevel@tonic-gate 		argvec += 2;
7097c478bd9Sstevel@tonic-gate 	}
7107c478bd9Sstevel@tonic-gate 	check_var_consistency(adv_pr->adv_pr_config, save, sizeof (save));
7117c478bd9Sstevel@tonic-gate 	if (argcount != 0)
7127c478bd9Sstevel@tonic-gate 		logmsg(LOG_ERR, "Trailing text <%s> ignored\n", argvec[0]);
7137c478bd9Sstevel@tonic-gate }
7147c478bd9Sstevel@tonic-gate 
7157c478bd9Sstevel@tonic-gate /*
7167c478bd9Sstevel@tonic-gate  * Returns true if ok (and *resp updated) and false if failed.
7177c478bd9Sstevel@tonic-gate  */
7187c478bd9Sstevel@tonic-gate static boolean_t
parse_onoff(char * str,uint_t * resp)7197c478bd9Sstevel@tonic-gate parse_onoff(char *str, uint_t *resp)
7207c478bd9Sstevel@tonic-gate {
7217c478bd9Sstevel@tonic-gate 	if (strcasecmp(str, "on") == 0) {
7227c478bd9Sstevel@tonic-gate 		*resp = 1;
7237c478bd9Sstevel@tonic-gate 		return (_B_TRUE);
7247c478bd9Sstevel@tonic-gate 	}
7257c478bd9Sstevel@tonic-gate 	if (strcasecmp(str, "off") == 0) {
7267c478bd9Sstevel@tonic-gate 		*resp = 0;
7277c478bd9Sstevel@tonic-gate 		return (_B_TRUE);
7287c478bd9Sstevel@tonic-gate 	}
7297c478bd9Sstevel@tonic-gate 	if (strcasecmp(str, "true") == 0) {
7307c478bd9Sstevel@tonic-gate 		*resp = 1;
7317c478bd9Sstevel@tonic-gate 		return (_B_TRUE);
7327c478bd9Sstevel@tonic-gate 	}
7337c478bd9Sstevel@tonic-gate 	if (strcasecmp(str, "false") == 0) {
7347c478bd9Sstevel@tonic-gate 		*resp = 0;
7357c478bd9Sstevel@tonic-gate 		return (_B_TRUE);
7367c478bd9Sstevel@tonic-gate 	}
7377c478bd9Sstevel@tonic-gate 	if (parse_int(str, resp)) {
7387c478bd9Sstevel@tonic-gate 		if (*resp == 0 || *resp == 1)
7397c478bd9Sstevel@tonic-gate 			return (_B_TRUE);
7407c478bd9Sstevel@tonic-gate 	}
7417c478bd9Sstevel@tonic-gate 	return (_B_FALSE);
7427c478bd9Sstevel@tonic-gate }
7437c478bd9Sstevel@tonic-gate 
7447c478bd9Sstevel@tonic-gate /*
7457c478bd9Sstevel@tonic-gate  * Returns true if ok (and *resp updated) and false if failed.
7467c478bd9Sstevel@tonic-gate  */
7477c478bd9Sstevel@tonic-gate static boolean_t
parse_int(char * str,uint_t * resp)7487c478bd9Sstevel@tonic-gate parse_int(char *str, uint_t *resp)
7497c478bd9Sstevel@tonic-gate {
7507c478bd9Sstevel@tonic-gate 	char *end;
7517c478bd9Sstevel@tonic-gate 	int res;
7527c478bd9Sstevel@tonic-gate 
7537c478bd9Sstevel@tonic-gate 	res = strtoul(str, &end, 0);
7547c478bd9Sstevel@tonic-gate 	if (end == str)
7557c478bd9Sstevel@tonic-gate 		return (_B_FALSE);
7567c478bd9Sstevel@tonic-gate 	*resp = res;
7577c478bd9Sstevel@tonic-gate 	return (_B_TRUE);
7587c478bd9Sstevel@tonic-gate }
7597c478bd9Sstevel@tonic-gate 
7607c478bd9Sstevel@tonic-gate /*
7617c478bd9Sstevel@tonic-gate  * Parse something with a unit of millseconds.
7627c478bd9Sstevel@tonic-gate  * Regognizes the suffixes "ms", "s", "m", "h", and "d".
7637c478bd9Sstevel@tonic-gate  *
7647c478bd9Sstevel@tonic-gate  * Returns true if ok (and *resp updated) and false if failed.
7657c478bd9Sstevel@tonic-gate  */
7667c478bd9Sstevel@tonic-gate static boolean_t
parse_ms(char * str,uint_t * resp)7677c478bd9Sstevel@tonic-gate parse_ms(char *str, uint_t *resp)
7687c478bd9Sstevel@tonic-gate {
7697c478bd9Sstevel@tonic-gate 	/* Look at the last and next to last character */
7707c478bd9Sstevel@tonic-gate 	char *cp, *last, *nlast;
7717c478bd9Sstevel@tonic-gate 	char str2[BUFSIZ];	/* For local modification */
7727c478bd9Sstevel@tonic-gate 	int multiplier = 1;
7737c478bd9Sstevel@tonic-gate 
7747c478bd9Sstevel@tonic-gate 	(void) strncpy(str2, str, sizeof (str2));
7757c478bd9Sstevel@tonic-gate 	str2[sizeof (str2) - 1] = '\0';
7767c478bd9Sstevel@tonic-gate 
7777c478bd9Sstevel@tonic-gate 	last = str2;
7787c478bd9Sstevel@tonic-gate 	nlast = NULL;
7797c478bd9Sstevel@tonic-gate 	for (cp = str2; *cp != '\0'; cp++) {
7807c478bd9Sstevel@tonic-gate 		nlast = last;
7817c478bd9Sstevel@tonic-gate 		last = cp;
7827c478bd9Sstevel@tonic-gate 	}
7837c478bd9Sstevel@tonic-gate 	if (debug & D_PARSE) {
7847c478bd9Sstevel@tonic-gate 		logmsg(LOG_DEBUG, "parse_ms: last <%c> nlast <%c>\n",
7857c478bd9Sstevel@tonic-gate 		    (last != NULL ? *last : ' '),
7867c478bd9Sstevel@tonic-gate 		    (nlast != NULL ? *nlast : ' '));
7877c478bd9Sstevel@tonic-gate 	}
7887c478bd9Sstevel@tonic-gate 	switch (*last) {
7897c478bd9Sstevel@tonic-gate 	case 'd':
7907c478bd9Sstevel@tonic-gate 		multiplier *= 24;
7917c478bd9Sstevel@tonic-gate 		/* FALLTHRU */
7927c478bd9Sstevel@tonic-gate 	case 'h':
7937c478bd9Sstevel@tonic-gate 		multiplier *= 60;
7947c478bd9Sstevel@tonic-gate 		/* FALLTHRU */
7957c478bd9Sstevel@tonic-gate 	case 'm':
7967c478bd9Sstevel@tonic-gate 		multiplier *= 60;
7977c478bd9Sstevel@tonic-gate 		*last = '\0';
7987c478bd9Sstevel@tonic-gate 		multiplier *= 1000;	/* Convert to milliseconds */
7997c478bd9Sstevel@tonic-gate 		break;
8007c478bd9Sstevel@tonic-gate 	case 's':
8017c478bd9Sstevel@tonic-gate 		/* Could be "ms" or "s" */
8027c478bd9Sstevel@tonic-gate 		if (nlast != NULL && *nlast == 'm') {
8037c478bd9Sstevel@tonic-gate 			/* "ms" */
8047c478bd9Sstevel@tonic-gate 			*nlast = '\0';
8057c478bd9Sstevel@tonic-gate 		} else {
8067c478bd9Sstevel@tonic-gate 			*last = '\0';
8077c478bd9Sstevel@tonic-gate 			multiplier *= 1000;	/* Convert to milliseconds */
8087c478bd9Sstevel@tonic-gate 		}
8097c478bd9Sstevel@tonic-gate 		break;
8107c478bd9Sstevel@tonic-gate 	}
8117c478bd9Sstevel@tonic-gate 
8127c478bd9Sstevel@tonic-gate 	if (!parse_int(str2, resp))
8137c478bd9Sstevel@tonic-gate 		return (_B_FALSE);
8147c478bd9Sstevel@tonic-gate 
8157c478bd9Sstevel@tonic-gate 	*resp *= multiplier;
8167c478bd9Sstevel@tonic-gate 	return (_B_TRUE);
8177c478bd9Sstevel@tonic-gate }
8187c478bd9Sstevel@tonic-gate 
8197c478bd9Sstevel@tonic-gate /*
8207c478bd9Sstevel@tonic-gate  * Parse something with a unit of seconds.
8217c478bd9Sstevel@tonic-gate  * Regognizes the suffixes "s", "m", "h", and "d".
8227c478bd9Sstevel@tonic-gate  *
8237c478bd9Sstevel@tonic-gate  * Returns true if ok (and *resp updated) and false if failed.
8247c478bd9Sstevel@tonic-gate  */
8257c478bd9Sstevel@tonic-gate static boolean_t
parse_s(char * str,uint_t * resp)8267c478bd9Sstevel@tonic-gate parse_s(char *str, uint_t *resp)
8277c478bd9Sstevel@tonic-gate {
8287c478bd9Sstevel@tonic-gate 	/* Look at the last character */
8297c478bd9Sstevel@tonic-gate 	char *cp, *last;
8307c478bd9Sstevel@tonic-gate 	char str2[BUFSIZ];	/* For local modification */
8317c478bd9Sstevel@tonic-gate 	int multiplier = 1;
8327c478bd9Sstevel@tonic-gate 
8337c478bd9Sstevel@tonic-gate 	(void) strncpy(str2, str, sizeof (str2));
8347c478bd9Sstevel@tonic-gate 	str2[sizeof (str2) - 1] = '\0';
8357c478bd9Sstevel@tonic-gate 
8367c478bd9Sstevel@tonic-gate 	last = str2;
8377c478bd9Sstevel@tonic-gate 	for (cp = str2; *cp != '\0'; cp++) {
8387c478bd9Sstevel@tonic-gate 		last = cp;
8397c478bd9Sstevel@tonic-gate 	}
8407c478bd9Sstevel@tonic-gate 	if (debug & D_PARSE) {
8417c478bd9Sstevel@tonic-gate 		logmsg(LOG_DEBUG, "parse_s: last <%c>\n",
8427c478bd9Sstevel@tonic-gate 		    (last != NULL ? *last : ' '));
8437c478bd9Sstevel@tonic-gate 	}
8447c478bd9Sstevel@tonic-gate 	switch (*last) {
8457c478bd9Sstevel@tonic-gate 	case 'd':
8467c478bd9Sstevel@tonic-gate 		multiplier *= 24;
8477c478bd9Sstevel@tonic-gate 		/* FALLTHRU */
8487c478bd9Sstevel@tonic-gate 	case 'h':
8497c478bd9Sstevel@tonic-gate 		multiplier *= 60;
8507c478bd9Sstevel@tonic-gate 		/* FALLTHRU */
8517c478bd9Sstevel@tonic-gate 	case 'm':
8527c478bd9Sstevel@tonic-gate 		multiplier *= 60;
8537c478bd9Sstevel@tonic-gate 		/* FALLTHRU */
8547c478bd9Sstevel@tonic-gate 	case 's':
8557c478bd9Sstevel@tonic-gate 		*last = '\0';
8567c478bd9Sstevel@tonic-gate 		break;
8577c478bd9Sstevel@tonic-gate 	}
8587c478bd9Sstevel@tonic-gate 	if (!parse_int(str2, resp))
8597c478bd9Sstevel@tonic-gate 		return (_B_FALSE);
8607c478bd9Sstevel@tonic-gate 
8617c478bd9Sstevel@tonic-gate 	*resp *= multiplier;
8627c478bd9Sstevel@tonic-gate 	return (_B_TRUE);
8637c478bd9Sstevel@tonic-gate }
8647c478bd9Sstevel@tonic-gate 
8657c478bd9Sstevel@tonic-gate /*
8667c478bd9Sstevel@tonic-gate  * Return prefixlen (0 to 128) if ok; -1 if failed.
8677c478bd9Sstevel@tonic-gate  */
8687c478bd9Sstevel@tonic-gate static int
parse_addrprefix(char * strin,struct in6_addr * in6)8697c478bd9Sstevel@tonic-gate parse_addrprefix(char *strin, struct in6_addr *in6)
8707c478bd9Sstevel@tonic-gate {
8717c478bd9Sstevel@tonic-gate 	char str[BUFSIZ];	/* Local copy for modification */
8727c478bd9Sstevel@tonic-gate 	int prefixlen;
8737c478bd9Sstevel@tonic-gate 	char *cp;
8747c478bd9Sstevel@tonic-gate 	char *end;
8757c478bd9Sstevel@tonic-gate 
8767c478bd9Sstevel@tonic-gate 	(void) strncpy(str, strin, sizeof (str));
8777c478bd9Sstevel@tonic-gate 	str[sizeof (str) - 1] = '\0';
8787c478bd9Sstevel@tonic-gate 
8797c478bd9Sstevel@tonic-gate 	cp = strchr(str, '/');
8807c478bd9Sstevel@tonic-gate 	if (cp == NULL)
8817c478bd9Sstevel@tonic-gate 		return (-1);
8827c478bd9Sstevel@tonic-gate 	*cp = '\0';
8837c478bd9Sstevel@tonic-gate 	cp++;
8847c478bd9Sstevel@tonic-gate 
8857c478bd9Sstevel@tonic-gate 	prefixlen = strtol(cp, &end, 10);
8867c478bd9Sstevel@tonic-gate 	if (cp == end)
8877c478bd9Sstevel@tonic-gate 		return (-1);
8887c478bd9Sstevel@tonic-gate 
8897c478bd9Sstevel@tonic-gate 	if (prefixlen < 0 || prefixlen > IPV6_ABITS)
8907c478bd9Sstevel@tonic-gate 		return (-1);
8917c478bd9Sstevel@tonic-gate 
8927c478bd9Sstevel@tonic-gate 	if (inet_pton(AF_INET6, str, in6) != 1)
8937c478bd9Sstevel@tonic-gate 		return (-1);
8947c478bd9Sstevel@tonic-gate 
8957c478bd9Sstevel@tonic-gate 	return (prefixlen);
8967c478bd9Sstevel@tonic-gate }
8977c478bd9Sstevel@tonic-gate 
8987c478bd9Sstevel@tonic-gate /*
8997c478bd9Sstevel@tonic-gate  * Parse an absolute date using a datemsk config file.
9007c478bd9Sstevel@tonic-gate  * Return the difference (measured in seconds) between that date/time and
9017c478bd9Sstevel@tonic-gate  * the current date/time.
9027c478bd9Sstevel@tonic-gate  * If the date has passed return zero.
9037c478bd9Sstevel@tonic-gate  *
9047c478bd9Sstevel@tonic-gate  * Returns true if ok (and *resp updated) and false if failed.
9057c478bd9Sstevel@tonic-gate  * XXX Due to getdate limitations can not exceed year 2038.
9067c478bd9Sstevel@tonic-gate  */
9077c478bd9Sstevel@tonic-gate static boolean_t
parse_date(char * str,uint_t * resp)9087c478bd9Sstevel@tonic-gate parse_date(char *str, uint_t *resp)
9097c478bd9Sstevel@tonic-gate {
9107c478bd9Sstevel@tonic-gate 	struct tm *tm;
9117c478bd9Sstevel@tonic-gate 	struct timeval tvs;
9127c478bd9Sstevel@tonic-gate 	time_t time, ntime;
9137c478bd9Sstevel@tonic-gate 
9147c478bd9Sstevel@tonic-gate 	if (getenv("DATEMSK") == NULL) {
9157c478bd9Sstevel@tonic-gate 		(void) putenv("DATEMSK=/etc/inet/datemsk.ndpd");
9167c478bd9Sstevel@tonic-gate 	}
9177c478bd9Sstevel@tonic-gate 
9187c478bd9Sstevel@tonic-gate 	if (gettimeofday(&tvs, NULL) < 0) {
9197c478bd9Sstevel@tonic-gate 		logperror("gettimeofday");
9207c478bd9Sstevel@tonic-gate 		return (_B_FALSE);
9217c478bd9Sstevel@tonic-gate 	}
9227c478bd9Sstevel@tonic-gate 	time = tvs.tv_sec;
9237c478bd9Sstevel@tonic-gate 	tm = getdate(str);
9247c478bd9Sstevel@tonic-gate 	if (tm == NULL) {
9257c478bd9Sstevel@tonic-gate 		logmsg(LOG_ERR, "Bad date <%s> (error %d)\n",
9267c478bd9Sstevel@tonic-gate 		    str, getdate_err);
9277c478bd9Sstevel@tonic-gate 		return (_B_FALSE);
9287c478bd9Sstevel@tonic-gate 	}
9297c478bd9Sstevel@tonic-gate 
9307c478bd9Sstevel@tonic-gate 	ntime = mktime(tm);
9317c478bd9Sstevel@tonic-gate 
9327c478bd9Sstevel@tonic-gate 	if (debug & D_PARSE) {
9337c478bd9Sstevel@tonic-gate 		char buf[BUFSIZ];
9347c478bd9Sstevel@tonic-gate 
9357c478bd9Sstevel@tonic-gate 		(void) strftime(buf, sizeof (buf), "%Y-%m-%d %R %Z", tm);
9367c478bd9Sstevel@tonic-gate 		logmsg(LOG_DEBUG, "parse_date: <%s>, delta %ld seconds\n",
9377c478bd9Sstevel@tonic-gate 		    buf, ntime - time);
9387c478bd9Sstevel@tonic-gate 	}
9397c478bd9Sstevel@tonic-gate 	if (ntime < time) {
9407c478bd9Sstevel@tonic-gate 		conferr("Date in the past <%s>\n", str);
9417c478bd9Sstevel@tonic-gate 		*resp = 0;
9427c478bd9Sstevel@tonic-gate 		return (_B_TRUE);
9437c478bd9Sstevel@tonic-gate 	}
9447c478bd9Sstevel@tonic-gate 	*resp = (ntime - time);
9457c478bd9Sstevel@tonic-gate 	return (_B_TRUE);
9467c478bd9Sstevel@tonic-gate }
9477c478bd9Sstevel@tonic-gate 
9487c478bd9Sstevel@tonic-gate /* PRINTFLIKE1 */
9497c478bd9Sstevel@tonic-gate static void
conferr(char * fmt,...)9507c478bd9Sstevel@tonic-gate conferr(char *fmt, ...)
9517c478bd9Sstevel@tonic-gate {
9527c478bd9Sstevel@tonic-gate 	char msg[NDPD_LOGMSGSIZE];
9537c478bd9Sstevel@tonic-gate 	size_t slen;
9547c478bd9Sstevel@tonic-gate 
9557c478bd9Sstevel@tonic-gate 	va_list ap;
9567c478bd9Sstevel@tonic-gate 	va_start(ap, fmt);
9577c478bd9Sstevel@tonic-gate 
9587c478bd9Sstevel@tonic-gate 	(void) snprintf(msg, NDPD_LOGMSGSIZE, "%s line %d: ",
9597c478bd9Sstevel@tonic-gate 	    conf_filename, lineno);
9607c478bd9Sstevel@tonic-gate 	slen = strlen(msg);
9617c478bd9Sstevel@tonic-gate 	(void) vsnprintf(msg + slen, NDPD_LOGMSGSIZE - slen, fmt, ap);
9627c478bd9Sstevel@tonic-gate 
9637c478bd9Sstevel@tonic-gate 	logmsg(LOG_ERR, "%s", msg);
9647c478bd9Sstevel@tonic-gate 
9657c478bd9Sstevel@tonic-gate 	va_end(ap);
9667c478bd9Sstevel@tonic-gate }
9677c478bd9Sstevel@tonic-gate 
9687c478bd9Sstevel@tonic-gate static FILE *
open_conffile(char * filename)9697c478bd9Sstevel@tonic-gate open_conffile(char *filename)
9707c478bd9Sstevel@tonic-gate {
9717c478bd9Sstevel@tonic-gate 	if (strlcpy(conf_filename, filename, MAXPATHLEN) >= MAXPATHLEN) {
9727c478bd9Sstevel@tonic-gate 		logmsg(LOG_ERR, "config file pathname is too long\n");
9737c478bd9Sstevel@tonic-gate 		return (NULL);
9747c478bd9Sstevel@tonic-gate 	}
9757c478bd9Sstevel@tonic-gate 
9767c478bd9Sstevel@tonic-gate 	lineno = 0;
9777c478bd9Sstevel@tonic-gate 
9787c478bd9Sstevel@tonic-gate 	return (fopen(filename, "r"));
9797c478bd9Sstevel@tonic-gate 
9807c478bd9Sstevel@tonic-gate }
981