Project

General

Profile

Submit #2841 ยป rtadvd-rtadvctl.diff

git diff of imported changes applied to the DragonFly_4.2_RELEASE branch - cmusser, 09/18/2015 10:02 AM

View differences:

sys/netinet/icmp6.h
309 309
#define ND_OPT_MTU			5
310 310

  
311 311
#define ND_OPT_ROUTE_INFO		200	/* draft-ietf-ipngwg-router-preference, not officially assigned yet */
312
#define ND_OPT_RDNSS			25	/* RFC 6106 */
313
#define ND_OPT_DNSSL			31	/* RFC 6106 */
314
#define ND_OPT_MAX			31
315

  
312 316

  
313 317
struct nd_opt_prefix_info {	/* prefix information */
314 318
	u_int8_t	nd_opt_pi_type;
......
348 352
	/* prefix follows */
349 353
} __attribute__((__packed__));
350 354

  
355
struct nd_opt_rdnss {		/* RDNSS option (RFC 6106) */
356
	u_int8_t	nd_opt_rdnss_type;
357
	u_int8_t	nd_opt_rdnss_len;
358
	u_int16_t	nd_opt_rdnss_reserved;
359
	u_int32_t	nd_opt_rdnss_lifetime;
360
	/* followed by list of recursive DNS servers */
361
} __attribute__((__packed__));
362

  
363
struct nd_opt_dnssl {		/* DNSSL option (RFC 6106) */
364
	u_int8_t	nd_opt_dnssl_type;
365
	u_int8_t	nd_opt_dnssl_len;
366
	u_int16_t	nd_opt_dnssl_reserved;
367
	u_int32_t	nd_opt_dnssl_lifetime;
368
	/* followed by list of DNS search domains */
369
} __attribute__((__packed__));
370

  
351 371
/*
352 372
 * icmp6 namelookup
353 373
 */
usr.sbin/Makefile
104 104
	rpcbind \
105 105
	rrenumd \
106 106
	rtadvd \
107
	rtadvctl \
107 108
	rtprio \
108 109
	rtsold \
109 110
	rwhod \
usr.sbin/rtadvctl/Makefile
1
# $FreeBSD: stable/10/usr.sbin/rtadvctl/Makefile 224144 2011-07-17 19:24:54Z hrs $
2
#
3
.PATH:	${.CURDIR}/../rtadvd
4

  
5
PROG=	rtadvctl
6
MAN=	rtadvctl.8
7

  
8
SRCS=	rtadvctl.c control.c control_client.c if.c timer_subr.c
9

  
10
CFLAGS+= -I${.CURDIR} -I${.CURDIR}/../rtadvd
11
WARNS?=	1
12

  
13
.include <bsd.prog.mk>
usr.sbin/rtadvctl/rtadvctl.8
1
.\" Copyright (C) 2011 Hiroki Sato <hrs@FreeBSD.org>.
2
.\" All rights reserved.
3
.\"
4
.\" Redistribution and use in source and binary forms, with or without
5
.\" modification, are permitted provided that the following conditions
6
.\" are met:
7
.\" 1. Redistributions of source code must retain the above copyright
8
.\"    notice, this list of conditions and the following disclaimer.
9
.\" 2. Redistributions in binary form must reproduce the above copyright
10
.\"    notice, this list of conditions and the following disclaimer in the
11
.\"    documentation and/or other materials provided with the distribution.
12
.\"
13
.\" THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS
14
.\" IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
15
.\" LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
16
.\" FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
17
.\" PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
18
.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19
.\" (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
20
.\" SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22
.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23
.\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
24
.\" EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
.\"
26
.\" $FreeBSD: stable/10/usr.sbin/rtadvctl/rtadvctl.8 235873 2012-05-24 02:24:03Z wblock $
27
.\"
28
.Dd July 16, 2011
29
.Dt RTADVCTL 8
30
.Os
31
.Sh NAME
32
.Nm rtadvctl
33
.Nd control program for
34
.Xr rtadvd 8
35
daemon
36
.Sh SYNOPSIS
37
.Nm
38
.Op Fl v
39
.Ar subcommand
40
.Op Ar interface ...
41
.Sh DESCRIPTION
42
.Nm
43
is a utility that communicates with
44
.Xr rtadvd 8
45
daemon and displays information about Router Advertisement messages being
46
sent on each interface.
47
.Pp
48
This utility provides several options and subcommands.
49
The options are as follows:
50
.Bl -tag -width indent
51
.\"
52
.It Fl v
53
Increase verbosity level.
54
When specified once, the
55
.Nm
56
utility shows additional information about prefixes, RDNSS, and DNSSL
57
options.
58
When given twice, it additionally shows information about
59
inactive interfaces and some statistics.
60
.El
61
.Pp
62
The subcommands are as follows:
63
.Bl -tag -width indent
64
.\"
65
.It reload Op interfaces...
66
Specifies to reload the configuration file.  If one or more
67
.Ar interface
68
is specified, configuration entries for the interfaces will be reloaded
69
selectively.
70
.It enable interfaces...
71
Specifies to mark the interface as enable and to try to reload the
72
configuration entry.
73
This subcommand is useful for dynamically-added interfaces.
74
.Pp
75
The
76
.Xr rtadvd 8
77
daemon marks an interface as enable if the interface exists and the
78
configuration file has a valid entry for that when it is invoked.
79
.It disable interfaces...
80
Specifies to mark the interface as disable.
81
.It shutdown
82
Makes the
83
.Xr rtadvd 8
84
daemon shut down.
85
Note that the
86
.Xr rtadvd 8
87
daemon will send several RAs with zero lifetime to invalidate the old
88
information on each interface.
89
It will take at most nine seconds.
90
.It show Op interfaces...
91
Displays information on Router Advertisement messages being sent
92
on each interface.
93
.El
94
.Sh SEE ALSO
95
.Xr rtadvd 8 ,
96
.Xr rtadvd.conf 5
97
.Sh HISTORY
98
The
99
.Nm
100
command first appeared in
101
.Fx 9.0 .
102
.Sh AUTHORS
103
.Nm
104
was written by
105
.An "Hiroki Sato" Aq hrs@FreeBSD.org .
usr.sbin/rtadvctl/rtadvctl.c
1
/*-
2
 * Copyright (C) 2011 Hiroki Sato <hrs@FreeBSD.org>
3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
7
 * are met:
8
 * 1. Redistributions of source code must retain the above copyright
9
 *    notice, this list of conditions and the following disclaimer.
10
 * 2. Redistributions in binary form must reproduce the above copyright
11
 *    notice, this list of conditions and the following disclaimer in the
12
 *    documentation and/or other materials provided with the distribution.
13
 *
14
 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
15
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS
18
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
21
 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
24
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
 *
26
 * $FreeBSD: stable/10/usr.sbin/rtadvctl/rtadvctl.c 253970 2013-08-05 20:13:02Z hrs $
27
 *
28
 */
29

  
30
#include <sys/queue.h>
31
#include <sys/types.h>
32
#include <sys/socket.h>
33
#include <sys/stat.h>
34
#include <sys/un.h>
35
#include <sys/uio.h>
36
#include <net/if.h>
37
#include <net/if_dl.h>
38
#include <net/if_types.h>
39
#include <net/if_var.h>
40
#include <net/ethernet.h>
41
#include <netinet/in.h>
42
#include <netinet/ip6.h>
43
#include <netinet/icmp6.h>
44
#include <netinet6/in6_var.h>
45
#include <netinet6/nd6.h>
46
#include <arpa/inet.h>
47
#include <fcntl.h>
48
#include <errno.h>
49
#include <inttypes.h>
50
#include <netdb.h>
51
#include <unistd.h>
52
#include <string.h>
53
#include <stdarg.h>
54
#include <stdio.h>
55
#include <stdlib.h>
56
#include <stdarg.h>
57
#include <syslog.h>
58
#include <time.h>
59
#include <err.h>
60

  
61
#include "pathnames.h"
62
#include "rtadvd.h"
63
#include "if.h"
64
#include "timer_subr.h"
65
#include "timer.h"
66
#include "control.h"
67
#include "control_client.h"
68

  
69
#define RA_IFSTATUS_INACTIVE	0
70
#define RA_IFSTATUS_RA_RECV	1
71
#define RA_IFSTATUS_RA_SEND	2
72

  
73
static int vflag = LOG_ERR;
74

  
75
static void	usage(void);
76

  
77
static int	action_propset(char *);
78
static int	action_propget(char *, struct ctrl_msg_pl *);
79
static int	action_plgeneric(int, char *, char *);
80

  
81
static int	action_enable(int, char **);
82
static int	action_disable(int, char **);
83
static int	action_reload(int, char **);
84
static int	action_echo(int, char **);
85
static int	action_version(int, char **);
86
static int	action_shutdown(int, char **);
87

  
88
static int	action_show(int, char **);
89
static int	action_show_prefix(struct prefix *);
90
static int	action_show_rtinfo(struct rtinfo *);
91
static int	action_show_rdnss(void *);
92
static int	action_show_dnssl(void *);
93

  
94
static int	csock_client_open(struct sockinfo *);
95
static size_t	dname_labeldec(char *, size_t, const char *);
96
static void	mysyslog(int, const char *, ...);
97

  
98
static const char *rtpref_str[] = {
99
	"medium",		/* 00 */
100
	"high",			/* 01 */
101
	"rsv",			/* 10 */
102
	"low"			/* 11 */
103
};
104

  
105
static struct dispatch_table {
106
	const char	*dt_comm;
107
	int (*dt_act)(int, char **);
108
} dtable[] = {
109
	{ "show", action_show },
110
	{ "reload", action_reload },
111
	{ "shutdown", action_shutdown },
112
	{ "enable", action_enable },
113
	{ "disable", action_disable },
114
	{ NULL, NULL },
115
	{ "echo", action_echo },
116
	{ "version", action_version },
117
	{ NULL, NULL },
118
};
119

  
120
static char errmsgbuf[1024];
121
static char *errmsg = NULL;
122

  
123
static void
124
mysyslog(int priority, const char * restrict fmt, ...)
125
{
126
	va_list ap;
127

  
128
	if (vflag >= priority) {
129
		va_start(ap, fmt);
130
		vfprintf(stderr, fmt, ap);
131
		fprintf(stderr, "\n");
132
		va_end(ap);
133
	}
134
}
135

  
136
static void
137
usage(void)
138
{
139
	int i;
140

  
141
	for (i = 0; (size_t)i < sizeof(dtable)/sizeof(dtable[0]); i++) {
142
		if (dtable[i].dt_comm == NULL)
143
			break;
144
		printf("%s\n", dtable[i].dt_comm);
145
	}
146

  
147
	exit(1);
148
}
149

  
150
int
151
main(int argc, char *argv[])
152
{
153
	int i;
154
	int ch;
155
	int (*action)(int, char **) = NULL;
156
	int error;
157

  
158
	while ((ch = getopt(argc, argv, "Dv")) != -1) {
159
		switch (ch) {
160
		case 'D':
161
			vflag = LOG_DEBUG;
162
			break;
163
		case 'v':
164
			vflag++;
165
			break;
166
		default:
167
			usage();
168
		}
169
	}
170
	argc -= optind;
171
	argv += optind;
172

  
173
	if (argc == 0)
174
		usage();
175

  
176
	for (i = 0; (size_t)i < sizeof(dtable)/sizeof(dtable[0]); i++) {
177
		if (dtable[i].dt_comm == NULL ||
178
		    strcmp(dtable[i].dt_comm, argv[0]) == 0) {
179
			action = dtable[i].dt_act;
180
			break;
181
		}
182
	}
183

  
184
	if (action == NULL)
185
		usage();
186

  
187
	error = (dtable[i].dt_act)(--argc, ++argv);
188
	if (error) {
189
		fprintf(stderr, "%s failed", dtable[i].dt_comm);
190
		if (errmsg != NULL)
191
			fprintf(stderr, ": %s", errmsg);
192
		fprintf(stderr, ".\n");
193
	}
194

  
195
	return (error);
196
}
197

  
198
static int
199
csock_client_open(struct sockinfo *s)
200
{
201
	struct sockaddr_un sun;
202

  
203
	if ((s->si_fd = socket(PF_UNIX, SOCK_STREAM, 0)) == -1)
204
		err(1, "cannot open control socket.");
205

  
206
	memset(&sun, 0, sizeof(sun));
207
	sun.sun_family = AF_UNIX;
208
	sun.sun_len = sizeof(sun);
209
	strlcpy(sun.sun_path, s->si_name, sizeof(sun.sun_path));
210

  
211
	if (connect(s->si_fd, (struct sockaddr *)&sun, sizeof(sun)) == -1)
212
		err(1, "connect: %s", s->si_name);
213

  
214
	mysyslog(LOG_DEBUG,
215
	    "<%s> connected to %s", __func__, sun.sun_path);
216

  
217
	return (0);
218
}
219

  
220
static int
221
action_plgeneric(int action, char *plstr, char *buf)
222
{
223
	struct ctrl_msg_hdr *cm;
224
	struct ctrl_msg_pl cp;
225
	struct sockinfo *s;
226
	char *msg;
227
	char *p;
228
	char *q;
229

  
230
	s = &ctrlsock;
231
	csock_client_open(s);
232

  
233
	cm = (struct ctrl_msg_hdr *)buf;
234
	msg = (char *)buf + sizeof(*cm);
235

  
236
	cm->cm_version = CM_VERSION;
237
	cm->cm_type = action;
238
	cm->cm_len = sizeof(*cm);
239

  
240
	if (plstr != NULL) {
241
		memset(&cp, 0, sizeof(cp));
242
		p = strchr(plstr, ':');
243
		q = strchr(plstr, '=');
244
		if (p != NULL && q != NULL && p > q)
245
			return (1);
246

  
247
		if (p == NULL) {		/* No : */
248
			cp.cp_ifname = NULL;
249
			cp.cp_key = plstr;
250
		} else if  (p == plstr) {	/* empty */
251
			cp.cp_ifname = NULL;
252
			cp.cp_key = plstr + 1;
253
		} else {
254
			*p++ = '\0';
255
			cp.cp_ifname = plstr;
256
			cp.cp_key = p;
257
		}
258
		if (q == NULL)
259
			cp.cp_val = NULL;
260
		else {
261
			*q++ = '\0';
262
			cp.cp_val = q;
263
		}
264
		cm->cm_len += cm_pl2bin(msg, &cp);
265

  
266
		mysyslog(LOG_DEBUG, "<%s> key=%s, val_len=%d, ifname=%s",
267
		    __func__,cp.cp_key, cp.cp_val_len, cp.cp_ifname);
268
	}
269

  
270
	return (cm_handler_client(s->si_fd, CM_STATE_MSG_DISPATCH, buf));
271
}
272

  
273
static int
274
action_propget(char *argv, struct ctrl_msg_pl *cp)
275
{
276
	int error;
277
	struct ctrl_msg_hdr *cm;
278
	char buf[CM_MSG_MAXLEN];
279
	char *msg;
280

  
281
	memset(cp, 0, sizeof(*cp));
282
	cm = (struct ctrl_msg_hdr *)buf;
283
	msg = (char *)buf + sizeof(*cm);
284

  
285
	error = action_plgeneric(CM_TYPE_REQ_GET_PROP, argv, buf);
286
	if (error || cm->cm_len <= sizeof(*cm))
287
		return (1);
288

  
289
	cm_bin2pl(msg, cp);
290
	mysyslog(LOG_DEBUG, "<%s> type=%d, len=%d",
291
	    __func__, cm->cm_type, cm->cm_len);
292
	mysyslog(LOG_DEBUG, "<%s> key=%s, val_len=%d, ifname=%s",
293
	    __func__,cp->cp_key, cp->cp_val_len, cp->cp_ifname);
294

  
295
	return (0);
296
}
297

  
298
static int
299
action_propset(char *argv)
300
{
301
	char buf[CM_MSG_MAXLEN];
302

  
303
	return (action_plgeneric(CM_TYPE_REQ_SET_PROP, argv, buf));
304
}
305

  
306
static int
307
action_disable(int argc, char **argv)
308
{
309
	char *action_argv;
310
	char argv_disable[IFNAMSIZ + sizeof(":disable=")];
311
	int i;
312
	int error;
313

  
314
	if (argc < 1)
315
		return (1);
316

  
317
	error = 0;
318
	for (i = 0; i < argc; i++) {
319
		sprintf(argv_disable, "%s:disable=", argv[i]);
320
		action_argv = argv_disable;
321
		error += action_propset(action_argv);
322
	}
323

  
324
	return (error);
325
}
326

  
327
static int
328
action_enable(int argc, char **argv)
329
{
330
	char *action_argv;
331
	char argv_enable[IFNAMSIZ + sizeof(":enable=")];
332
	int i;
333
	int error;
334

  
335
	if (argc < 1)
336
		return (1);
337

  
338
	error = 0;
339
	for (i = 0; i < argc; i++) {
340
		sprintf(argv_enable, "%s:enable=", argv[i]);
341
		action_argv = argv_enable;
342
		error += action_propset(action_argv);
343
	}
344

  
345
	return (error);
346
}
347

  
348
static int
349
action_reload(int argc, char **argv)
350
{
351
	char *action_argv;
352
	char argv_reload[IFNAMSIZ + sizeof(":reload=")];
353
	int i;
354
	int error;
355

  
356
	if (argc == 0) {
357
		action_argv = strdup(":reload=");
358
		return (action_propset(action_argv));
359
	}
360

  
361
	error = 0;
362
	for (i = 0; i < argc; i++) {
363
		sprintf(argv_reload, "%s:reload=", argv[i]);
364
		action_argv = argv_reload;
365
		error += action_propset(action_argv);
366
	}
367

  
368
	return (error);
369
}
370

  
371
static int
372
action_echo(int argc __unused, char **argv __unused)
373
{
374
	char *action_argv;
375

  
376
	action_argv = strdup("echo");
377
	return (action_propset(action_argv));
378
}
379

  
380
static int
381
action_shutdown(int argc __unused, char **argv __unused)
382
{
383
	char *action_argv;
384

  
385
	action_argv = strdup("shutdown");
386
	return (action_propset(action_argv));
387
}
388

  
389
/* XXX */
390
static int
391
action_version(int argc __unused, char **argv __unused)
392
{
393
	char *action_argv;
394
	struct ctrl_msg_pl cp;
395
	int error;
396

  
397
	action_argv = strdup(":version=");
398
	error = action_propget(action_argv, &cp);
399
	if (error)
400
		return (error);
401

  
402
	printf("version=%s\n", cp.cp_val);
403
	return (0);
404
}
405

  
406
static int
407
action_show(int argc, char **argv)
408
{
409
	char *action_argv;
410
	char argv_ifilist[sizeof(":ifilist=")] = ":ifilist=";
411
	char argv_ifi[IFNAMSIZ + sizeof(":ifi=")];
412
	char argv_rai[IFNAMSIZ + sizeof(":rai=")];
413
	char argv_rti[IFNAMSIZ + sizeof(":rti=")];
414
	char argv_pfx[IFNAMSIZ + sizeof(":pfx=")];
415
	char argv_ifi_ra_timer[IFNAMSIZ + sizeof(":ifi_ra_timer=")];
416
	char argv_rdnss[IFNAMSIZ + sizeof(":rdnss=")];
417
	char argv_dnssl[IFNAMSIZ + sizeof(":dnssl=")];
418
	char ssbuf[SSBUFLEN];
419

  
420
	struct timespec now, ts0, ts;
421
	struct ctrl_msg_pl cp;
422
	struct ifinfo *ifi;
423
	TAILQ_HEAD(, ifinfo) ifl = TAILQ_HEAD_INITIALIZER(ifl);
424
	char *endp;
425
	char *p;
426
	int error;
427
	int i;
428
	int len;
429

  
430
	if (argc == 0) {
431
		action_argv = argv_ifilist;
432
		error = action_propget(action_argv, &cp);
433
		if (error)
434
			return (error);
435

  
436
		p = cp.cp_val;
437
		endp = p + cp.cp_val_len;
438
		while (p < endp) {
439
			ifi = malloc(sizeof(*ifi));
440
			if (ifi == NULL)
441
				return (1);
442
			memset(ifi, 0, sizeof(*ifi));
443

  
444
			strcpy(ifi->ifi_ifname, p);
445
			ifi->ifi_ifindex = if_nametoindex(ifi->ifi_ifname);
446
			TAILQ_INSERT_TAIL(&ifl, ifi, ifi_next);
447
			p += strlen(ifi->ifi_ifname) + 1;
448
		}
449
	} else {
450
		for (i = 0; i < argc; i++) {
451
			ifi = malloc(sizeof(*ifi));
452
			if (ifi == NULL)
453
				return (1);
454
			memset(ifi, 0, sizeof(*ifi));
455

  
456
			strcpy(ifi->ifi_ifname, argv[i]);
457
			ifi->ifi_ifindex = if_nametoindex(ifi->ifi_ifname);
458
			if (ifi->ifi_ifindex == 0) {
459
				sprintf(errmsgbuf, "invalid interface %s",
460
				    ifi->ifi_ifname);
461
				errmsg = errmsgbuf;
462
				return (1);
463
			}
464

  
465
			TAILQ_INSERT_TAIL(&ifl, ifi, ifi_next);
466
		}
467
	}
468

  
469
	clock_gettime(CLOCK_REALTIME_FAST, &now);
470
	clock_gettime(CLOCK_MONOTONIC_FAST, &ts);
471
	TS_SUB(&now, &ts, &ts0);
472

  
473
	TAILQ_FOREACH(ifi, &ifl, ifi_next) {
474
		struct ifinfo *ifi_s;
475
		struct rtadvd_timer *rat;
476
		struct rainfo *rai;
477
		struct rtinfo *rti;
478
		struct prefix *pfx;
479
		int c;
480
		int ra_ifstatus;
481

  
482
		sprintf(argv_ifi, "%s:ifi=", ifi->ifi_ifname);
483
		action_argv = argv_ifi;
484
		error = action_propget(action_argv, &cp);
485
		if (error)
486
			return (error);
487
		ifi_s = (struct ifinfo *)cp.cp_val;
488

  
489
		if (!(ifi_s->ifi_persist) && vflag < LOG_NOTICE)
490
			continue;
491

  
492
		printf("%s: flags=<", ifi->ifi_ifname);
493

  
494
		c = 0;
495
		if (ifi_s->ifi_ifindex == 0)
496
			c += printf("NONEXISTENT");
497
		else
498
			c += printf("%s", (ifi_s->ifi_flags & IFF_UP) ?
499
			    "UP" : "DOWN");
500
		switch (ifi_s->ifi_state) {
501
		case IFI_STATE_CONFIGURED:
502
			c += printf("%s%s", (c) ? "," : "", "CONFIGURED");
503
			break;
504
		case IFI_STATE_TRANSITIVE:
505
			c += printf("%s%s", (c) ? "," : "", "TRANSITIVE");
506
			break;
507
		}
508
		if (ifi_s->ifi_persist)
509
			c += printf("%s%s", (c) ? "," : "", "PERSIST");
510
		printf(">");
511

  
512
		ra_ifstatus = RA_IFSTATUS_INACTIVE;
513
		if ((ifi_s->ifi_flags & IFF_UP) &&
514
		    ((ifi_s->ifi_state == IFI_STATE_CONFIGURED) ||
515
			(ifi_s->ifi_state == IFI_STATE_TRANSITIVE))) {
516
#if (__FreeBSD_version < 900000)
517
			/*
518
			 * RA_RECV: !ip6.forwarding && ip6.accept_rtadv
519
			 * RA_SEND: ip6.forwarding
520
			 */
521
			if (getinet6sysctl(IPV6CTL_FORWARDING) == 0) {
522
				if (getinet6sysctl(IPV6CTL_ACCEPT_RTADV))
523
					ra_ifstatus = RA_IFSTATUS_RA_RECV;
524
				else
525
					ra_ifstatus = RA_IFSTATUS_INACTIVE;
526
			} else
527
				ra_ifstatus = RA_IFSTATUS_RA_SEND;
528
#else
529
			/*
530
			 * RA_RECV: ND6_IFF_ACCEPT_RTADV
531
			 * RA_SEND: ip6.forwarding
532
			 */
533
			if (ifi_s->ifi_nd_flags & ND6_IFF_ACCEPT_RTADV)
534
				ra_ifstatus = RA_IFSTATUS_RA_RECV;
535
			else if (getinet6sysctl(IPV6CTL_FORWARDING))
536
				ra_ifstatus = RA_IFSTATUS_RA_SEND;
537
			else
538
				ra_ifstatus = RA_IFSTATUS_INACTIVE;
539
#endif
540
		}
541

  
542
		c = 0;
543
		printf(" status=<");
544
		if (ra_ifstatus == RA_IFSTATUS_INACTIVE)
545
			printf("%s%s", (c) ? "," : "", "INACTIVE");
546
		else if (ra_ifstatus == RA_IFSTATUS_RA_RECV)
547
			printf("%s%s", (c) ? "," : "", "RA_RECV");
548
		else if (ra_ifstatus == RA_IFSTATUS_RA_SEND)
549
			printf("%s%s", (c) ? "," : "", "RA_SEND");
550
		printf("> ");
551

  
552
		switch (ifi_s->ifi_state) {
553
		case IFI_STATE_CONFIGURED:
554
		case IFI_STATE_TRANSITIVE:
555
			break;
556
		default:
557
			printf("\n");
558
			continue;
559
		}
560

  
561
		printf("mtu %d\n", ifi_s->ifi_phymtu);
562

  
563
		sprintf(argv_rai, "%s:rai=", ifi->ifi_ifname);
564
		action_argv = argv_rai;
565

  
566
		error = action_propget(action_argv, &cp);
567
		if (error)
568
			continue;
569

  
570
		rai = (struct rainfo *)cp.cp_val;
571

  
572
		printf("\tDefaultLifetime: %s",
573
		    sec2str(rai->rai_lifetime, ssbuf));
574
		if (ra_ifstatus != RA_IFSTATUS_RA_SEND &&
575
		    rai->rai_lifetime == 0)
576
			printf(" (RAs will be sent with zero lifetime)");
577

  
578
		printf("\n");
579

  
580
		printf("\tMinAdvInterval/MaxAdvInterval: ");
581
		printf("%s/", sec2str(rai->rai_mininterval, ssbuf));
582
		printf("%s\n", sec2str(rai->rai_maxinterval, ssbuf));
583
		if (rai->rai_linkmtu)
584
			printf("\tAdvLinkMTU: %d", rai->rai_linkmtu);
585
		else
586
			printf("\tAdvLinkMTU: <none>");
587

  
588
		printf(", ");
589

  
590
		printf("Flags: ");
591
		if (rai->rai_managedflg || rai->rai_otherflg) {
592
			printf("%s", rai->rai_managedflg ? "M" : "");
593
			printf("%s", rai->rai_otherflg ? "O" : "");
594
		} else
595
			printf("<none>");
596

  
597
		printf(", ");
598

  
599
		printf("Preference: %s\n",
600
		    rtpref_str[(rai->rai_rtpref >> 3) & 0xff]);
601

  
602
		printf("\tReachableTime: %s, ",
603
		    sec2str(rai->rai_reachabletime, ssbuf));
604
		printf("RetransTimer: %s, "
605
		    "CurHopLimit: %d\n",
606
		    sec2str(rai->rai_retranstimer, ssbuf),
607
		    rai->rai_hoplimit);
608
		printf("\tAdvIfPrefixes: %s\n",
609
		    rai->rai_advifprefix ? "yes" : "no");
610

  
611
		/* RA timer */
612
		rat = NULL;
613
		if (ifi_s->ifi_ra_timer != NULL) {
614
			sprintf(argv_ifi_ra_timer, "%s:ifi_ra_timer=",
615
			    ifi->ifi_ifname);
616
			action_argv = argv_ifi_ra_timer;
617

  
618
			error = action_propget(action_argv, &cp);
619
			if (error)
620
				return (error);
621

  
622
			rat = (struct rtadvd_timer *)cp.cp_val;
623
		}
624
		printf("\tNext RA send: ");
625
		if (rat == NULL)
626
			printf("never\n");
627
		else {
628
			ts.tv_sec = rat->rat_tm.tv_sec + ts0.tv_sec;
629
			printf("%s", ctime(&ts.tv_sec));
630
		}
631
		printf("\tLast RA send: ");
632
		if (ifi_s->ifi_ra_lastsent.tv_sec == 0)
633
			printf("never\n");
634
		else {
635
			ts.tv_sec = ifi_s->ifi_ra_lastsent.tv_sec + ts0.tv_sec;
636
			printf("%s", ctime(&ts.tv_sec));
637
		}
638
		if (rai->rai_clockskew)
639
			printf("\tClock skew: %" PRIu16 "sec\n",
640
			    rai->rai_clockskew);
641

  
642
		if (vflag < LOG_WARNING)
643
			continue;
644

  
645
		/* route information */
646
		sprintf(argv_rti, "%s:rti=", ifi->ifi_ifname);
647
		action_argv = argv_rti;
648
		error = action_propget(action_argv, &cp);
649
		if (error)
650
			return (error);
651

  
652
		rti = (struct rtinfo *)cp.cp_val;
653
		len = cp.cp_val_len / sizeof(*rti);
654
		if (len > 0) {
655
			printf("\tRoute Info:\n");
656

  
657
			for (i = 0; i < len; i++)
658
				action_show_rtinfo(&rti[i]);
659
		}
660

  
661
		/* prefix information */
662
		sprintf(argv_pfx, "%s:pfx=", ifi->ifi_ifname);
663
		action_argv = argv_pfx;
664

  
665
		error = action_propget(action_argv, &cp);
666
		if (error)
667
			continue;
668

  
669
		pfx = (struct prefix *)cp.cp_val;
670
		len = cp.cp_val_len / sizeof(*pfx);
671

  
672
		if (len > 0) {
673
			printf("\tPrefixes (%d):\n", len);
674

  
675
			for (i = 0; i < len; i++)
676
				action_show_prefix(&pfx[i]);
677
		}
678

  
679
		/* RDNSS information */
680
		sprintf(argv_rdnss, "%s:rdnss=", ifi->ifi_ifname);
681
		action_argv = argv_rdnss;
682

  
683
		error = action_propget(action_argv, &cp);
684
		if (error)
685
			continue;
686

  
687
		len = *((uint16_t *)cp.cp_val);
688

  
689
		if (len > 0) {
690
			printf("\tRDNSS entries:\n");
691
			action_show_rdnss(cp.cp_val);
692
		}
693

  
694
		/* DNSSL information */
695
		sprintf(argv_dnssl, "%s:dnssl=", ifi->ifi_ifname);
696
		action_argv = argv_dnssl;
697

  
698
		error = action_propget(action_argv, &cp);
699
		if (error)
700
			continue;
701

  
702
		len = *((uint16_t *)cp.cp_val);
703

  
704
		if (len > 0) {
705
			printf("\tDNSSL entries:\n");
706
			action_show_dnssl(cp.cp_val);
707
		}
708

  
709
		if (vflag < LOG_NOTICE)
710
			continue;
711

  
712
		printf("\n");
713

  
714
		printf("\tCounters\n"
715
		    "\t RA burst counts: %" PRIu16 " (interval: %s)\n"
716
		    "\t RS wait counts: %" PRIu16 "\n",
717
		    ifi_s->ifi_burstcount,
718
		    sec2str(ifi_s->ifi_burstinterval, ssbuf),
719
		    ifi_s->ifi_rs_waitcount);
720

  
721
		printf("\tOutputs\n"
722
		    "\t RA: %" PRIu64 "\n", ifi_s->ifi_raoutput);
723

  
724
		printf("\tInputs\n"
725
		    "\t RA: %" PRIu64 " (normal)\n"
726
		    "\t RA: %" PRIu64 " (inconsistent)\n"
727
		    "\t RS: %" PRIu64 "\n",
728
		    ifi_s->ifi_rainput,
729
		    ifi_s->ifi_rainconsistent,
730
		    ifi_s->ifi_rsinput);
731

  
732
		printf("\n");
733

  
734
#if 0	/* Not implemented yet */
735
		printf("\tReceived RAs:\n");
736
#endif
737
	}
738

  
739
	return (0);
740
}
741

  
742
static int
743
action_show_rtinfo(struct rtinfo *rti)
744
{
745
	char ntopbuf[INET6_ADDRSTRLEN];
746
	char ssbuf[SSBUFLEN];
747

  
748
	printf("\t  %s/%d (pref: %s, ltime: %s)\n",
749
	    inet_ntop(AF_INET6, &rti->rti_prefix,
750
		ntopbuf, sizeof(ntopbuf)),
751
	    rti->rti_prefixlen,
752
	    rtpref_str[0xff & (rti->rti_rtpref >> 3)],
753
	    (rti->rti_ltime == ND6_INFINITE_LIFETIME) ?
754
	    "infinity" : sec2str(rti->rti_ltime, ssbuf));
755

  
756
	return (0);
757
}
758

  
759
static int
760
action_show_prefix(struct prefix *pfx)
761
{
762
	char ntopbuf[INET6_ADDRSTRLEN];
763
	char ssbuf[SSBUFLEN];
764
	struct timespec now;
765

  
766
	clock_gettime(CLOCK_MONOTONIC_FAST, &now);
767
	printf("\t  %s/%d", inet_ntop(AF_INET6, &pfx->pfx_prefix,
768
		ntopbuf, sizeof(ntopbuf)), pfx->pfx_prefixlen);
769

  
770
	printf(" (");
771
	switch (pfx->pfx_origin) {
772
	case PREFIX_FROM_KERNEL:
773
		printf("KERNEL");
774
		break;
775
	case PREFIX_FROM_CONFIG:
776
		printf("CONFIG");
777
		break;
778
	case PREFIX_FROM_DYNAMIC:
779
		printf("DYNAMIC");
780
		break;
781
	}
782

  
783
	printf(",");
784

  
785
	printf(" vltime=%s",
786
	    (pfx->pfx_validlifetime == ND6_INFINITE_LIFETIME) ?
787
	    "infinity" : sec2str(pfx->pfx_validlifetime, ssbuf));
788

  
789
	if (pfx->pfx_vltimeexpire > 0)
790
		printf("(expire: %s)",
791
		    ((long)pfx->pfx_vltimeexpire > now.tv_sec) ?
792
		    sec2str(pfx->pfx_vltimeexpire - now.tv_sec, ssbuf) :
793
		    "0");
794

  
795
	printf(",");
796

  
797
	printf(" pltime=%s",
798
	    (pfx->pfx_preflifetime == ND6_INFINITE_LIFETIME) ?
799
	    "infinity" : sec2str(pfx->pfx_preflifetime, ssbuf));
800

  
801
	if (pfx->pfx_pltimeexpire > 0)
802
		printf("(expire %s)",
803
		    ((long)pfx->pfx_pltimeexpire > now.tv_sec) ?
804
		    sec2str(pfx->pfx_pltimeexpire - now.tv_sec, ssbuf) :
805
		    "0");
806

  
807
	printf(",");
808

  
809
	printf(" flags=");
810
	if (pfx->pfx_onlinkflg || pfx->pfx_autoconfflg) {
811
		printf("%s", pfx->pfx_onlinkflg ? "L" : "");
812
		printf("%s", pfx->pfx_autoconfflg ? "A" : "");
813
	} else
814
		printf("<none>");
815

  
816
	if (pfx->pfx_timer) {
817
		struct timespec *rest;
818

  
819
		rest = rtadvd_timer_rest(pfx->pfx_timer);
820
		if (rest) { /* XXX: what if not? */
821
			printf(" expire=%s", sec2str(rest->tv_sec, ssbuf));
822
		}
823
	}
824

  
825
	printf(")\n");
826

  
827
	return (0);
828
}
829

  
830
static int
831
action_show_rdnss(void *msg)
832
{
833
	struct rdnss *rdn;
834
	struct rdnss_addr *rda;
835
	uint16_t *rdn_cnt;
836
	uint16_t *rda_cnt;
837
	int i;
838
	int j;
839
	char *p;
840
	uint32_t	ltime;
841
	char ntopbuf[INET6_ADDRSTRLEN];
842
	char ssbuf[SSBUFLEN];
843

  
844
	p = msg;
845
	rdn_cnt = (uint16_t *)p;
846
	p += sizeof(*rdn_cnt);
847

  
848
	if (*rdn_cnt > 0) {
849
		for (i = 0; i < *rdn_cnt; i++) {
850
			rdn = (struct rdnss *)p;
851
			ltime = rdn->rd_ltime;
852
			p += sizeof(*rdn);
853

  
854
			rda_cnt = (uint16_t *)p;
855
			p += sizeof(*rda_cnt);
856
			if (*rda_cnt > 0)
857
				for (j = 0; j < *rda_cnt; j++) {
858
					rda = (struct rdnss_addr *)p;
859
					printf("\t  %s (ltime=%s)\n",
860
					    inet_ntop(AF_INET6,
861
						&rda->ra_dns,
862
						ntopbuf,
863
						sizeof(ntopbuf)),
864
					    sec2str(ltime, ssbuf));
865
					p += sizeof(*rda);
866
				}
867
		}
868
	}
869

  
870
	return (0);
871
}
872

  
873
static int
874
action_show_dnssl(void *msg)
875
{
876
	struct dnssl *dns;
877
	struct dnssl_addr *dna;
878
	uint16_t *dns_cnt;
879
	uint16_t *dna_cnt;
880
	int i;
881
	int j;
882
	char *p;
883
	uint32_t ltime;
884
	char hbuf[NI_MAXHOST];
885
	char ssbuf[SSBUFLEN];
886

  
887
	p = msg;
888
	dns_cnt = (uint16_t *)p;
889
	p += sizeof(*dns_cnt);
890

  
891
	if (*dns_cnt > 0) {
892
		for (i = 0; i < *dns_cnt; i++) {
893
			dns = (struct dnssl *)p;
894
			ltime = dns->dn_ltime;
895
			p += sizeof(*dns);
896

  
897
			dna_cnt = (uint16_t *)p;
898
			p += sizeof(*dna_cnt);
899
			if (*dna_cnt > 0)
900
				for (j = 0; j < *dna_cnt; j++) {
901
					dna = (struct dnssl_addr *)p;
902
					dname_labeldec(hbuf, sizeof(hbuf),
903
					    dna->da_dom);
904
					printf("\t  %s (ltime=%s)\n",
905
					    hbuf, sec2str(ltime, ssbuf));
906
					p += sizeof(*dna);
907
				}
908
		}
909
	}
910

  
911
	return (0);
912
}
913

  
914
/* Decode domain name label encoding in RFC 1035 Section 3.1 */
915
static size_t
916
dname_labeldec(char *dst, size_t dlen, const char *src)
917
{
918
	size_t len;
919
	const char *src_origin;
920
	const char *src_last;
921
	const char *dst_origin;
922

  
923
	src_origin = src;
924
	src_last = strchr(src, '\0');
925
	dst_origin = dst;
926
	memset(dst, '\0', dlen);
927
	while (src && (len = (uint8_t)(*src++) & 0x3f) &&
928
	    (src + len) <= src_last) {
929
		if (dst != dst_origin)
930
			*dst++ = '.';
931
		mysyslog(LOG_DEBUG, "<%s> labellen = %zd", __func__, len);
932
		memcpy(dst, src, len);
933
		src += len;
934
		dst += len;
935
	}
936
	*dst = '\0';
937

  
938
	return (src - src_origin);
939
}
usr.sbin/rtadvd/Makefile
11 11
# AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT
12 12
# LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
13 13
# A PARTICULAR PURPOSE.
14
# $FreeBSD: src/usr.sbin/rtadvd/Makefile,v 1.1.2.2 2001/04/25 12:10:48 ru Exp $
14
#
15
# $FreeBSD: stable/10/usr.sbin/rtadvd/Makefile 224144 2011-07-17 19:24:54Z hrs $
15 16

  
16 17
PROG=	rtadvd
17
SRCS=	rtadvd.c rrenum.c advcap.c if.c config.c timer.c dump.c
18
WARNS?=	2
18
MAN=	rtadvd.conf.5 rtadvd.8
19
SRCS=	rtadvd.c rrenum.c advcap.c if.c config.c timer.c timer_subr.c	\
20
	control.c control_server.c
19 21

  
20
CFLAGS+=-DINET6
22
DPADD=	${LIBUTIL}
23
LDADD=	-lutil
21 24

  
22
MAN=	rtadvd.conf.5 rtadvd.8
25
CFLAGS+= -DHAVE_ARC4RANDOM
26

  
27
WARNS?=	1
23 28

  
24 29
.include <bsd.prog.mk>
usr.sbin/rtadvd/advcap.c
1
/*	$KAME: advcap.c,v 1.5 2001/02/01 09:12:08 jinmei Exp $	*/
1
/*	$FreeBSD: stable/10/usr.sbin/rtadvd/advcap.c 222824 2011-06-07 15:40:17Z hrs $	*/
2
/*	$KAME: advcap.c,v 1.11 2003/05/19 09:46:50 keiichi Exp $	*/
2 3

  
3 4
/*
4 5
 * Copyright (c) 1983 The Regents of the University of California.
......
12 13
 * 2. Redistributions in binary form must reproduce the above copyright
13 14
 *    notice, this list of conditions and the following disclaimer in the
14 15
 *    documentation and/or other materials provided with the distribution.
15
 * 3. Neither the name of the University nor the names of its contributors
16
 * 4. Neither the name of the University nor the names of its contributors
16 17
 *    may be used to endorse or promote products derived from this software
17 18
 *    without specific prior written permission.
18 19
 *
......
27 28
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 29
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 30
 * SUCH DAMAGE.
30
 *
31
 * $FreeBSD: src/usr.sbin/rtadvd/advcap.c,v 1.1.2.2 2001/07/03 11:02:13 ume Exp $
32
 * $DragonFly: src/usr.sbin/rtadvd/advcap.c,v 1.5 2005/02/17 14:00:10 joerg Exp $
33 31
 */
34 32

  
35 33
/*
......
66 64
#define V_TERM		"HOST"
67 65
#endif
68 66

  
69
char	*RM;
70

  
71 67
/*
72 68
 * termcap - routines for dealing with the terminal capability data base
73 69
 *
......
85 81
static	char *tbuf;
86 82
static	int hopcount;	/* detect infinite loops in termcap, init 0 */
87 83

  
88
static	char *remotefile;
89

  
90
extern char *conffile;
84
extern const char *conffile;
91 85

  
92 86
int tgetent(char *, char *);
93
int getent(char *, char *, char *);
87
int getent(char *, char *, const char *);
94 88
int tnchktc(void);
95 89
int tnamatch(char *);
96 90
static char *tskip(char *);
97
long long tgetnum(char *);
91
int64_t tgetnum(char *);
98 92
int tgetflag(char *);
99 93
char *tgetstr(char *, char **);
100 94
static char *tdecode(char *, char **);
......
107 101
int
108 102
tgetent(char *bp, char *name)
109 103
{
110
	char *cp;
111

  
112
	remotefile = cp = conffile ? conffile : _PATH_RTADVDCONF;
113
	return (getent(bp, name, cp));
104
	return (getent(bp, name, conffile));
114 105
}
115 106

  
116 107
int
117
getent(char *bp, char *name, char *cp)
108
getent(char *bp, char *name, const char *cfile)
118 109
{
119 110
	int c;
120 111
	int i = 0, cnt = 0;
121 112
	char ibuf[BUFSIZ];
113
	char *cp;
122 114
	int tf;
123 115

  
124 116
	tbuf = bp;
......
130 122
	 * use so we don't have to read the file. In this case it
131 123
	 * has to already have the newlines crunched out.
132 124
	 */
133
	if (cp && *cp) {
134
		tf = open(RM = cp, O_RDONLY);
135
	}
125
	if (cfile && *cfile)
126
		tf = open(cfile, O_RDONLY);
127

  
136 128
	if (tf < 0) {
137 129
		syslog(LOG_INFO,
138 130
		       "<%s> open: %s", __func__, strerror(errno));
......
157 149
				}
158 150
				break;
159 151
			}
160
			if (cp >= bp+BUFSIZ) {
161
				write(2,"Remcap entry too long\n", 23);
152
			if (cp >= bp + BUFSIZ) {
153
				write(STDERR_FILENO, "Remcap entry too long\n",
154
				      23);
162 155
				break;
163 156
			} else
164 157
				*cp++ = c;
......
193 186

  
194 187
	p = tbuf + strlen(tbuf) - 2;	/* before the last colon */
195 188
	while (*--p != ':')
196
		if (p<tbuf) {
197
			write(2, "Bad remcap entry\n", 18);
189
		if (p < tbuf) {
190
			write(STDERR_FILENO, "Bad remcap entry\n", 18);
198 191
			return (0);
199 192
		}
200 193
	p++;
201 194
	/* p now points to beginning of last field */
202 195
	if (p[0] != 't' || p[1] != 'c')
203 196
		return (1);
204
	strcpy(tcname, p+3);
197
	strlcpy(tcname, p + 3, sizeof tcname);
205 198
	q = tcname;
206 199
	while (*q && *q != ':')
207 200
		q++;
208 201
	*q = 0;
209 202
	if (++hopcount > MAXHOP) {
210
		write(2, "Infinite tc= loop\n", 18);
203
		write(STDERR_FILENO, "Infinite tc= loop\n", 18);
211 204
		return (0);
212 205
	}
213
	if (getent(tcbuf, tcname, remotefile) != 1) {
206
	if (getent(tcbuf, tcname, conffile) != 1) {
214 207
		return (0);
215 208
	}
216 209
	for (q = tcbuf; *q++ != ':'; )
217 210
		;
218 211
	l = p - holdtbuf + strlen(q);
219 212
	if (l > BUFSIZ) {
220
		write(2, "Remcap entry too long\n", 23);
213
		write(STDERR_FILENO, "Remcap entry too long\n", 23);
221 214
		q[BUFSIZ - (p-holdtbuf)] = 0;
222 215
	}
223 216
	strcpy(p, q);
......
301 294
 * a # character.  If the option is not found we return -1.
302 295
 * Note that we handle octal numbers beginning with 0.
303 296
 */
304
long long
297
int64_t
305 298
tgetnum(char *id)
306 299
{
307
	long long i;
300
	int64_t i;
308 301
	int base;
309 302
	char *bp = tbuf;
310 303

  
......
385 378
}
386 379

  
387 380
/*
388
 * Tdecode does the grunt work to decode the
381
 * Tdecode does the grung work to decode the
389 382
 * string capability escapes.
390 383
 */
391 384
static char *
......
393 386
{
394 387
	char *cp;
395 388
	int c;
396
	char *dp;
389
	const char *dp;
397 390
	int i;
398 391
	char term;
399 392

  
usr.sbin/rtadvd/advcap.h
1
/*	$KAME: advcap.h,v 1.3 2001/02/01 09:12:08 jinmei Exp $	*/
1
/*	$FreeBSD: stable/10/usr.sbin/rtadvd/advcap.h 173412 2007-11-07 10:53:41Z kevlo $	*/
2
/*	$KAME: advcap.h,v 1.5 2003/06/09 05:40:54 t-momose Exp $	*/
2 3

  
3 4
/*
4 5
 * Copyright (C) 1994,1995 by Andrey A. Chernov, Moscow, Russia.
......
24 25
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 26
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 27
 * SUCH DAMAGE.
27
 *
28
 * $FreeBSD: src/usr.sbin/rtadvd/advcap.h,v 1.1.2.2 2001/07/03 11:02:14 ume Exp $
29
 * $DragonFly: src/usr.sbin/rtadvd/advcap.h,v 1.3 2003/11/03 19:31:42 eirikn Exp $
30 28
 */
31 29

  
32 30
/* Based on Id: termcap.h,v 1.8 1996/09/10 12:42:10 peter Exp */
......
40 38

  
41 39
extern int agetent(char *, const char *);
42 40
extern int agetflag(const char *);
43
extern long long agetnum(const char *);
41
extern int64_t agetnum(const char *);
44 42
extern char *agetstr(const char *, char **);
45 43

  
46 44
__END_DECLS
usr.sbin/rtadvd/config.c
1
/*	$KAME: config.c,v 1.37 2001/05/25 07:34:00 itojun Exp $	*/
1
/*	$FreeBSD: stable/10/usr.sbin/rtadvd/config.c 254955 2013-08-27 11:50:33Z hrs $	*/
2
/*	$KAME: config.c,v 1.84 2003/08/05 12:34:23 itojun Exp $	*/
2 3

  
3 4
/*
4 5
 * Copyright (C) 1998 WIDE Project.
6
 * Copyright (C) 2011 Hiroki Sato <hrs@FreeBSD.org>
5 7
 * All rights reserved.
6
 * 
8
 *
7 9
 * Redistribution and use in source and binary forms, with or without
8 10
 * modification, are permitted provided that the following conditions
9 11
 * are met:
......
15 17
 * 3. Neither the name of the project nor the names of its contributors
16 18
 *    may be used to endorse or promote products derived from this software
17 19
 *    without specific prior written permission.
18
 * 
20
 *
19 21
 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
20 22
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 23
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
......
27 29
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 30
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 31
 * SUCH DAMAGE.
30
 *
31
 * $FreeBSD: src/usr.sbin/rtadvd/config.c,v 1.3.2.5 2003/04/22 09:40:57 suz Exp $
32 32
 */
33 33

  
34 34
#include <sys/param.h>
35 35
#include <sys/ioctl.h>
36 36
#include <sys/socket.h>
37
#include <sys/time.h>
38
#include <sys/sysctl.h>
39 37

  
40 38
#include <net/if.h>
41
#if defined(__DragonFly__) 
42 39
#include <net/if_var.h>
43
#endif /* __DragonFly__  */
44 40
#include <net/route.h>
45 41
#include <net/if_dl.h>
46 42

  
......
49 45
#include <netinet/ip6.h>
50 46
#include <netinet6/ip6_var.h>
51 47
#include <netinet/icmp6.h>
52
#ifdef MIP6
53
#include <netinet6/mip6.h>
54
#endif
48
#include <netinet6/nd6.h>
55 49

  
56 50
#include <arpa/inet.h>
57 51

  
58 52
#include <stdio.h>
59 53
#include <syslog.h>
60 54
#include <errno.h>
55
#include <inttypes.h>
56
#include <netdb.h>
61 57
#include <string.h>
62
#include <stdlib.h>
63 58
#include <search.h>
59
#include <stdlib.h>
60
#include <time.h>
64 61
#include <unistd.h>
65 62
#include <ifaddrs.h>
66 63

  
......
70 67
#include "if.h"
71 68
#include "config.h"
72 69

  
70
/* label of tcapcode + number + domain name + zero octet */
71
static char entbuf[10 + 3 + NI_MAXHOST + 1];
72
static char oentbuf[10 + 3 + NI_MAXHOST + 1];
73
static char abuf[DNAME_LABELENC_MAXLEN];
74

  
73 75
static time_t prefix_timo = (60 * 120);	/* 2 hours.
74 76
					 * XXX: should be configurable. */
75
extern struct rainfo *ralist;
76 77

  
77 78
static struct rtadvd_timer *prefix_timeout(void *);
78
static void makeentry(char *, size_t, int, char *, int);
79
static void get_prefix(struct rainfo *);
80
static int getinet6sysctl(int);
79
static void makeentry(char *, size_t, int, const char *);
80
static size_t dname_labelenc(char *, const char *);
81 81

  
82
void
83
getconfig(char *intface)
82
/* Encode domain name label encoding in RFC 1035 Section 3.1 */
83
static size_t
84
dname_labelenc(char *dst, const char *src)
84 85
{
85
	int stat, pfxs, i;
86
	char tbuf[BUFSIZ];
87
	struct rainfo *tmp;
88
	long val;
89
	long long val64;
90
	char buf[BUFSIZ];
91
	char *bp = buf;
92
	char *addr;
93
	static int forwarding = -1;
86
	char *dst_origin;
87
	char *p;
88
	size_t len;
89

  
90
	dst_origin = dst;
91
	len = strlen(src);
92

  
93
	/* Length fields per 63 octets + '\0' (<= DNAME_LABELENC_MAXLEN) */
94
	memset(dst, 0, len + len / 64 + 1 + 1);
95

  
96
	syslog(LOG_DEBUG, "<%s> labelenc = %s", __func__, src);
97
	while (src && (len = strlen(src)) != 0) {
98
		/* Put a length field with 63 octet limitation first. */
99
		p = strchr(src, '.');
100
		if (p == NULL)
101
			*dst++ = len = MIN(63, len);
102
		else
103
			*dst++ = len = MIN(63, p - src);
104
		/* Copy 63 octets at most. */
105
		memcpy(dst, src, len);
106
		dst += len;
107
		if (p == NULL) /* the last label */
108
			break;
109
		src = p + 1;
110
	}
111
	/* Always need a 0-length label at the tail. */
112
	*dst++ = '\0';
113

  
114
	syslog(LOG_DEBUG, "<%s> labellen = %td", __func__, dst - dst_origin);
115
	return (dst - dst_origin);
116
}
94 117

  
95
#define MUSTHAVE(var, cap)	\
118
#define	MUSTHAVE(var, cap)						\
96 119
    do {								\
... This diff was truncated because it exceeds the maximum size that can be displayed.
    (1-1/1)