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