xref: /aosp_15_r20/external/iputils/ninfod/ninfod.h (revision bd1f8aeb6080fa6544ec30aeca3eb4da100f359f)
1*bd1f8aebSAndroid Build Coastguard Worker /* $USAGI: ninfod.h,v 1.20 2002-12-19 15:51:16 yoshfuji Exp $ */
2*bd1f8aebSAndroid Build Coastguard Worker /*
3*bd1f8aebSAndroid Build Coastguard Worker  * Copyright (C) 2002 USAGI/WIDE Project.
4*bd1f8aebSAndroid Build Coastguard Worker  * All rights reserved.
5*bd1f8aebSAndroid Build Coastguard Worker  *
6*bd1f8aebSAndroid Build Coastguard Worker  * Redistribution and use in source and binary forms, with or without
7*bd1f8aebSAndroid Build Coastguard Worker  * modification, are permitted provided that the following conditions
8*bd1f8aebSAndroid Build Coastguard Worker  * are met:
9*bd1f8aebSAndroid Build Coastguard Worker  * 1. Redistributions of source code must retain the above copyright
10*bd1f8aebSAndroid Build Coastguard Worker  *    notice, this list of conditions and the following disclaimer.
11*bd1f8aebSAndroid Build Coastguard Worker  * 2. Redistributions in binary form must reproduce the above copyright
12*bd1f8aebSAndroid Build Coastguard Worker  *    notice, this list of conditions and the following disclaimer in the
13*bd1f8aebSAndroid Build Coastguard Worker  *    documentation and/or other materials provided with the distribution.
14*bd1f8aebSAndroid Build Coastguard Worker  * 3. Neither the name of the project nor the names of its contributors
15*bd1f8aebSAndroid Build Coastguard Worker  *    may be used to endorse or promote products derived from this software
16*bd1f8aebSAndroid Build Coastguard Worker  *    without specific prior written permission.
17*bd1f8aebSAndroid Build Coastguard Worker  *
18*bd1f8aebSAndroid Build Coastguard Worker  * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
19*bd1f8aebSAndroid Build Coastguard Worker  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20*bd1f8aebSAndroid Build Coastguard Worker  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21*bd1f8aebSAndroid Build Coastguard Worker  * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
22*bd1f8aebSAndroid Build Coastguard Worker  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23*bd1f8aebSAndroid Build Coastguard Worker  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24*bd1f8aebSAndroid Build Coastguard Worker  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25*bd1f8aebSAndroid Build Coastguard Worker  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26*bd1f8aebSAndroid Build Coastguard Worker  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27*bd1f8aebSAndroid Build Coastguard Worker  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28*bd1f8aebSAndroid Build Coastguard Worker  * SUCH DAMAGE.
29*bd1f8aebSAndroid Build Coastguard Worker  */
30*bd1f8aebSAndroid Build Coastguard Worker /*
31*bd1f8aebSAndroid Build Coastguard Worker  * Author:
32*bd1f8aebSAndroid Build Coastguard Worker  * 	YOSHIFUJI Hideaki <[email protected]>
33*bd1f8aebSAndroid Build Coastguard Worker  */
34*bd1f8aebSAndroid Build Coastguard Worker 
35*bd1f8aebSAndroid Build Coastguard Worker /* definitions */
36*bd1f8aebSAndroid Build Coastguard Worker #define NINFOD			"ninfod"
37*bd1f8aebSAndroid Build Coastguard Worker #define NINFOD_PIDFILE		"/var/run/ninfod.pid"
38*bd1f8aebSAndroid Build Coastguard Worker 
39*bd1f8aebSAndroid Build Coastguard Worker #define	MAX_ANYCAST_DELAY_TIME	1000000.0	/* 1 sec */
40*bd1f8aebSAndroid Build Coastguard Worker 
41*bd1f8aebSAndroid Build Coastguard Worker #define MAX_DNSLABEL_SIZE	63
42*bd1f8aebSAndroid Build Coastguard Worker #define MAX_DNSNAME_SIZE	255
43*bd1f8aebSAndroid Build Coastguard Worker #define MAX_QUERY_SIZE		(sizeof(struct icmp6_nodeinfo)+MAX_DNSNAME_SIZE+2)
44*bd1f8aebSAndroid Build Coastguard Worker #define MAX_REPLY_SIZE		1280-sizeof(struct ip6_hdr)
45*bd1f8aebSAndroid Build Coastguard Worker 
46*bd1f8aebSAndroid Build Coastguard Worker #define MAX_SUPTYPES		32
47*bd1f8aebSAndroid Build Coastguard Worker 
48*bd1f8aebSAndroid Build Coastguard Worker #define CHECKANDFILL_ARGS	struct packetcontext *p,\
49*bd1f8aebSAndroid Build Coastguard Worker 				char *subject, size_t subjlen,	\
50*bd1f8aebSAndroid Build Coastguard Worker 				unsigned int flags,		\
51*bd1f8aebSAndroid Build Coastguard Worker 				unsigned int *subj_if,		\
52*bd1f8aebSAndroid Build Coastguard Worker 				int reply
53*bd1f8aebSAndroid Build Coastguard Worker #define INIT_ARGS		\
54*bd1f8aebSAndroid Build Coastguard Worker 				int forced
55*bd1f8aebSAndroid Build Coastguard Worker 
56*bd1f8aebSAndroid Build Coastguard Worker struct packetcontext {
57*bd1f8aebSAndroid Build Coastguard Worker 	/* socket */
58*bd1f8aebSAndroid Build Coastguard Worker 	int sock;
59*bd1f8aebSAndroid Build Coastguard Worker 
60*bd1f8aebSAndroid Build Coastguard Worker 	/* query info */
61*bd1f8aebSAndroid Build Coastguard Worker 	struct sockaddr_storage addr;
62*bd1f8aebSAndroid Build Coastguard Worker 	socklen_t addrlen;
63*bd1f8aebSAndroid Build Coastguard Worker 	struct in6_pktinfo pktinfo;
64*bd1f8aebSAndroid Build Coastguard Worker 	char query[MAX_QUERY_SIZE];
65*bd1f8aebSAndroid Build Coastguard Worker 	int querylen;
66*bd1f8aebSAndroid Build Coastguard Worker 
67*bd1f8aebSAndroid Build Coastguard Worker 	/* reply info */
68*bd1f8aebSAndroid Build Coastguard Worker 	struct icmp6_nodeinfo reply;	/* common */
69*bd1f8aebSAndroid Build Coastguard Worker 	char *replydata;		/* data */
70*bd1f8aebSAndroid Build Coastguard Worker 	int replydatalen;
71*bd1f8aebSAndroid Build Coastguard Worker 
72*bd1f8aebSAndroid Build Coastguard Worker 	unsigned int delay;		/* (random) delay */
73*bd1f8aebSAndroid Build Coastguard Worker };
74*bd1f8aebSAndroid Build Coastguard Worker 
75*bd1f8aebSAndroid Build Coastguard Worker /* variables */
76*bd1f8aebSAndroid Build Coastguard Worker extern int opt_v;		/* ninfod.c */
77*bd1f8aebSAndroid Build Coastguard Worker extern int daemonized;		/* ninfod.c */
78*bd1f8aebSAndroid Build Coastguard Worker extern int sock;		/* ninfod.c */
79*bd1f8aebSAndroid Build Coastguard Worker extern int initialized;		/* ninfod_core.c */
80*bd1f8aebSAndroid Build Coastguard Worker 
81*bd1f8aebSAndroid Build Coastguard Worker /* ninfod.c* */
82*bd1f8aebSAndroid Build Coastguard Worker int ni_recv(struct packetcontext *p);
83*bd1f8aebSAndroid Build Coastguard Worker int ni_send(struct packetcontext *p);
84*bd1f8aebSAndroid Build Coastguard Worker 
85*bd1f8aebSAndroid Build Coastguard Worker /* ninfod_core.c */
86*bd1f8aebSAndroid Build Coastguard Worker #if ENABLE_DEBUG
87*bd1f8aebSAndroid Build Coastguard Worker void stderrlog(int priority, char *format, ...);
88*bd1f8aebSAndroid Build Coastguard Worker # define DEBUG(pri, fmt, args...)	do {									\
89*bd1f8aebSAndroid Build Coastguard Worker 						int saved_errno = errno;					\
90*bd1f8aebSAndroid Build Coastguard Worker 						if (opt_v || pri != LOG_DEBUG) {				\
91*bd1f8aebSAndroid Build Coastguard Worker 							if (daemonized) {					\
92*bd1f8aebSAndroid Build Coastguard Worker 								syslog(pri, fmt, ## args);			\
93*bd1f8aebSAndroid Build Coastguard Worker 							} else {						\
94*bd1f8aebSAndroid Build Coastguard Worker 								stderrlog(pri, fmt, ## args);			\
95*bd1f8aebSAndroid Build Coastguard Worker 							}							\
96*bd1f8aebSAndroid Build Coastguard Worker 						}								\
97*bd1f8aebSAndroid Build Coastguard Worker 						errno = saved_errno;						\
98*bd1f8aebSAndroid Build Coastguard Worker 					} while(0)
99*bd1f8aebSAndroid Build Coastguard Worker #else
100*bd1f8aebSAndroid Build Coastguard Worker # define DEBUG(pri, fmt, args...)	do { ; } while(0)
101*bd1f8aebSAndroid Build Coastguard Worker #endif
102*bd1f8aebSAndroid Build Coastguard Worker 
103*bd1f8aebSAndroid Build Coastguard Worker #define ni_malloc(size)	({										\
104*bd1f8aebSAndroid Build Coastguard Worker 				size_t _size = (size);							\
105*bd1f8aebSAndroid Build Coastguard Worker 				void *p = malloc(_size);						\
106*bd1f8aebSAndroid Build Coastguard Worker 				DEBUG(LOG_DEBUG, "%s(): malloc(%zu) = %p\n", __func__, _size, p);	\
107*bd1f8aebSAndroid Build Coastguard Worker 				p;									\
108*bd1f8aebSAndroid Build Coastguard Worker 			})
109*bd1f8aebSAndroid Build Coastguard Worker #define ni_free(p)	({										\
110*bd1f8aebSAndroid Build Coastguard Worker 				void *_p = (p);								\
111*bd1f8aebSAndroid Build Coastguard Worker 				int saved_errno = errno;						\
112*bd1f8aebSAndroid Build Coastguard Worker 				DEBUG(LOG_DEBUG, "%s(): free(%p)\n", __func__, _p);			\
113*bd1f8aebSAndroid Build Coastguard Worker 				free(_p);								\
114*bd1f8aebSAndroid Build Coastguard Worker 				errno = saved_errno;							\
115*bd1f8aebSAndroid Build Coastguard Worker 			})
116*bd1f8aebSAndroid Build Coastguard Worker 
117*bd1f8aebSAndroid Build Coastguard Worker void init_core(int forced);
118*bd1f8aebSAndroid Build Coastguard Worker int pr_nodeinfo(struct packetcontext *p);
119*bd1f8aebSAndroid Build Coastguard Worker 
120*bd1f8aebSAndroid Build Coastguard Worker int pr_nodeinfo_unknown(CHECKANDFILL_ARGS);
121*bd1f8aebSAndroid Build Coastguard Worker int pr_nodeinfo_refused(CHECKANDFILL_ARGS);
122*bd1f8aebSAndroid Build Coastguard Worker int pr_nodeinfo_noop(CHECKANDFILL_ARGS);
123*bd1f8aebSAndroid Build Coastguard Worker void init_nodeinfo_suptypes(INIT_ARGS);
124*bd1f8aebSAndroid Build Coastguard Worker int pr_nodeinfo_suptypes(CHECKANDFILL_ARGS);
125*bd1f8aebSAndroid Build Coastguard Worker 
126*bd1f8aebSAndroid Build Coastguard Worker /* ninfod_addrs.c */
127*bd1f8aebSAndroid Build Coastguard Worker void init_nodeinfo_ipv6addr(INIT_ARGS);
128*bd1f8aebSAndroid Build Coastguard Worker int pr_nodeinfo_ipv6addr(CHECKANDFILL_ARGS);
129*bd1f8aebSAndroid Build Coastguard Worker void init_nodeinfo_ipv4addr(INIT_ARGS);
130*bd1f8aebSAndroid Build Coastguard Worker int pr_nodeinfo_ipv4addr(CHECKANDFILL_ARGS);
131*bd1f8aebSAndroid Build Coastguard Worker 
132*bd1f8aebSAndroid Build Coastguard Worker /* ninfod_name.c */
133*bd1f8aebSAndroid Build Coastguard Worker int check_nigroup(const struct in6_addr *addr);
134*bd1f8aebSAndroid Build Coastguard Worker void init_nodeinfo_nodename(INIT_ARGS);
135*bd1f8aebSAndroid Build Coastguard Worker int pr_nodeinfo_nodename(CHECKANDFILL_ARGS);
136*bd1f8aebSAndroid Build Coastguard Worker 
137