1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
/* $OpenBSD: printconf.c,v 1.2 2021/08/12 12:41:08 florian Exp $ */
/*
* Copyright (c) 2018 Florian Obser <florian@openbsd.org>
* Copyright (c) 2004, 2005 Esben Norby <norby@openbsd.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <sys/types.h>
#include <sys/queue.h>
#include <sys/socket.h>
#include <sys/uio.h>
#include <net/if.h>
#include <netinet/in.h>
#include <netinet/if_ether.h>
#include <arpa/inet.h>
#include <event.h>
#include <imsg.h>
#include <stdio.h>
#include <stdlib.h>
#include <vis.h>
#include "dhcpleased.h"
#include "log.h"
void print_dhcp_options(char *, uint8_t *, int);
void
print_dhcp_options(char *indent, uint8_t *p, int len)
{
static char buf[4 * 1500 + 1];
int rem, i;
uint8_t dho, dho_len, type;
rem = len;
while (rem > 0) {
dho = *p;
p += 1;
rem -= 1;
if (rem == 0)
fatal("dhcp option too short");
dho_len = *p;
p += 1;
rem -= 1;
if (rem < dho_len)
fatal("dhcp option too short: %d %d", rem, dho_len);
switch (dho) {
case DHO_DHCP_CLASS_IDENTIFIER:
strvisx(buf, p, dho_len, VIS_DQ | VIS_CSTYLE);
p += dho_len;
rem -= dho_len;
printf("%ssend vendor class id \"%s\"\n", indent, buf);
break;
case DHO_DHCP_CLIENT_IDENTIFIER:
if (dho_len < 1)
fatal("dhcp option too short");
type = *p;
p += 1;
rem -= 1;
switch (type) {
case HTYPE_NONE:
strvisx(buf, p, dho_len - 1, VIS_DQ |
VIS_CSTYLE);
printf("%ssend client id \"%s\"\n",
indent, buf);
break;
default:
printf("%ssend client id \"%02x",
indent, type);
for (i = 0; i < dho_len - 1; i++) {
printf(":%02x", *(p + i));
}
printf("\"\n");
break;
}
p += dho_len - 1;
rem -= dho_len - 1;
break;
default:
fatal("unknown dhcp option: %d [%d]", *p, rem);
break;
}
}
}
void
print_config(struct dhcpleased_conf *conf)
{
struct iface_conf *iface;
int i;
char hbuf[INET_ADDRSTRLEN];
SIMPLEQ_FOREACH(iface, &conf->iface_list, entry) {
printf("interface %s {\n", iface->name);
print_dhcp_options("\t", iface->c_id, iface->c_id_len);
print_dhcp_options("\t", iface->vc_id, iface->vc_id_len);
if (iface->ignore & IGN_DNS)
printf("\tignore dns\n");
if (iface->ignore & IGN_ROUTES)
printf("\tignore routes\n");
for (i = 0; i < iface->ignore_servers_len; i++) {
if (inet_ntop(AF_INET, &iface->ignore_servers[i],
hbuf, sizeof(hbuf)) == NULL)
continue;
printf("\tignore %s\n", hbuf);
}
printf("}\n");
}
}
|