1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_NDPD_DEFS_H
28 #define	_NDPD_DEFS_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include <strings.h>
35 #include <errno.h>
36 #include <sys/types.h>
37 #include <fcntl.h>
38 #include <signal.h>
39 #include <poll.h>
40 #include <unistd.h>
41 #include <time.h>
42 #include <stdarg.h>
43 #include <syslog.h>
44 
45 #include <sys/param.h>
46 #include <sys/socket.h>
47 #include <arpa/inet.h>
48 #include <netdb.h>
49 
50 #include <sys/ioctl.h>
51 #include <sys/sockio.h>
52 #include <net/if.h>
53 #include <sys/stropts.h>
54 
55 #include <string.h>
56 #include <ctype.h>
57 
58 #include <netinet/in_systm.h>
59 #include <netinet/in.h>
60 #include <netinet/ip.h>
61 #include <netinet/ip_icmp.h>
62 #include <netinet/if_ether.h>
63 #include <netinet/ip6.h>
64 #include <netinet/icmp6.h>
65 #include <net/route.h>
66 
67 #ifdef	__cplusplus
68 extern "C" {
69 #endif
70 
71 #define	PATH_NDPD_CONF	"/etc/inet/ndpd.conf"
72 #define	PATH_PID	"/var/run/in.ndpd.pid"
73 
74 extern int debug, no_loopback;
75 
76 extern struct in6_addr all_nodes_mcast;
77 extern struct in6_addr all_routers_mcast;
78 
79 extern int			rtsock;
80 extern struct	rt_msghdr	*rt_msg;
81 extern struct	sockaddr_in6	*rta_gateway;
82 extern struct	sockaddr_dl	*rta_ifp;
83 
84 /* Debug flags */
85 #define	D_ALL		0xffff
86 #define	D_DEFAULTS	0x0001		/* Default values in config file */
87 #define	D_CONFIG	0x0002		/* Config file */
88 #define	D_PHYINT	0x0004		/* phyint table */
89 #define	D_PREFIX	0x0008		/* prefix table */
90 #define	D_ROUTER	0x0010		/* router table */
91 #define	D_STATE		0x0020		/* RS/RA state machine */
92 #define	D_IFSCAN	0x0040		/* Scan of kernel interfaces */
93 #define	D_TIMER		0x0080		/* Timer mechanism */
94 #define	D_PARSE		0x0100		/* config file parser */
95 #define	D_PKTIN		0x0200		/* Received packet */
96 #define	D_PKTBAD	0x0400		/* Malformed packet */
97 #define	D_PKTOUT	0x0800		/* Sent packet */
98 #define	D_TMP		0x1000		/* RFC3041 mechanism */
99 #define	D_DAD		0x2000		/* Duplciate Address Detection */
100 
101 #define	IF_SEPARATOR		':'
102 #define	IPV6_MAX_HOPS		255
103 #define	IPV6_MIN_MTU		(1024+256)
104 #define	IPV6_ABITS		128
105 #define	TMP_TOKEN_BITS		64
106 #define	TMP_TOKEN_BYTES		(TMP_TOKEN_BITS / 8)
107 #define	MAX_DAD_FAILURES	5
108 
109 /* Return a random number from a an range inclusive of the endpoints */
110 #define	GET_RANDOM(LOW, HIGH) (random() % ((HIGH) - (LOW) + 1) + (LOW))
111 
112 #define	TIMER_INFINITY	0xFFFFFFFFU	/* Never time out */
113 #define	PREFIX_INFINITY 0XFFFFFFFFU	/* A "forever" prefix lifetime */
114 
115 /*
116  * Used by 2 hour rule for stateless addrconf
117  */
118 #define	MIN_VALID_LIFETIME	(2*60*60)		/* In seconds */
119 
120 /*
121  * Control how often pi_ReachableTime gets re-randomized
122  */
123 #define	MIN_REACH_RANDOM_INTERVAL	(60*1000)	/* 1 minute in ms */
124 #define	MAX_REACH_RANDOM_INTERVAL	(60*60*1000)	/* 1 hour in ms */
125 
126 /*
127  * Parsing constants
128  */
129 #define	MAXLINELEN	4096
130 #define	MAXARGSPERLINE	128
131 
132 void		timer_schedule(uint_t delay);
133 extern void	logmsg(int level, char *fmt, ...);
134 extern void	logperror(char *str);
135 extern int	parse_config(char *config_file, boolean_t file_required);
136 
137 extern int	poll_add(int fd);
138 extern int	poll_remove(int fd);
139 
140 extern char	*fmt_lla(char *llabuf, int bufsize, uchar_t *lla, int llalen);
141 
142 extern int	do_dad(char *ifname, struct sockaddr_in6 *testaddr);
143 
144 #ifdef	__cplusplus
145 }
146 #endif
147 
148 #endif	/* _NDPD_DEFS_H */
149