GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: usr.sbin/dhcrelay6/dhcpd.h Lines: 0 1 0.0 %
Date: 2017-11-13 Branches: 0 0 0.0 %

Line Branch Exec Source
1
/*	$OpenBSD: dhcpd.h,v 1.1 2017/03/17 14:45:16 rzalamena Exp $	*/
2
3
/*
4
 * Copyright (c) 2017 Rafael Zalamena <rzalamena@openbsd.org>
5
 * Copyright (c) 2004 Henning Brauer <henning@openbsd.org>
6
 * Copyright (c) 1995, 1996, 1997, 1998, 1999
7
 * The Internet Software Consortium.    All rights reserved.
8
 *
9
 * Redistribution and use in source and binary forms, with or without
10
 * modification, are permitted provided that the following conditions
11
 * are met:
12
 *
13
 * 1. Redistributions of source code must retain the above copyright
14
 *    notice, this list of conditions and the following disclaimer.
15
 * 2. Redistributions in binary form must reproduce the above copyright
16
 *    notice, this list of conditions and the following disclaimer in the
17
 *    documentation and/or other materials provided with the distribution.
18
 * 3. Neither the name of The Internet Software Consortium nor the names
19
 *    of its contributors may be used to endorse or promote products derived
20
 *    from this software without specific prior written permission.
21
 *
22
 * THIS SOFTWARE IS PROVIDED BY THE INTERNET SOFTWARE CONSORTIUM AND
23
 * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
24
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26
 * DISCLAIMED.  IN NO EVENT SHALL THE INTERNET SOFTWARE CONSORTIUM OR
27
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
30
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
31
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
33
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34
 * SUCH DAMAGE.
35
 *
36
 * This software has been written for the Internet Software Consortium
37
 * by Ted Lemon <mellon@fugue.com> in cooperation with Vixie
38
 * Enterprises.  To learn more about the Internet Software Consortium,
39
 * see ``http://www.vix.com/isc''.  To learn more about Vixie
40
 * Enterprises, see ``http://www.vix.com''.
41
 */
42
43
#ifndef _DHCPD_H_
44
#define _DHCPD_H_
45
46
#include <sys/queue.h>
47
48
#define DHCRELAY6_USER	"_dhcp"
49
50
/* Maximum size of client hardware address. */
51
#define CHADDR_SIZE	16
52
53
/* Packet context for assembly/disassembly. */
54
struct packet_ctx {
55
	/* Client or server socket descriptor. */
56
	int				 pc_sd;
57
58
	/* Layer 2 address information. */
59
	uint8_t				 pc_htype;
60
	uint8_t				 pc_hlen;
61
	uint8_t				 pc_smac[CHADDR_SIZE];
62
	uint8_t				 pc_dmac[CHADDR_SIZE];
63
64
	/* Layer 3 address information. */
65
	uint16_t			 pc_ethertype;
66
	struct sockaddr_storage		 pc_srcorig;
67
	struct sockaddr_storage		 pc_src;
68
	struct sockaddr_storage		 pc_dst;
69
70
	/* Relay Agent Information data. */
71
	uint8_t				*pc_raidata;
72
	size_t				 pc_raidatalen;
73
	uint32_t			 pc_enterpriseno;
74
	uint8_t				*pc_remote;
75
	size_t				 pc_remotelen;
76
};
77
78
struct hardware {
79
	u_int8_t htype;
80
	u_int8_t hlen;
81
	u_int8_t haddr[CHADDR_SIZE];
82
};
83
84
/* DHCP relaying modes. */
85
enum dhcp_relay_mode {
86
	DRM_UNKNOWN,
87
	DRM_LAYER2,
88
	DRM_LAYER3,
89
};
90
91
struct interface_info {
92
	struct hardware		 hw_address;
93
	struct in_addr		 primary_address;
94
	char			 name[IFNAMSIZ];
95
	int			 rfdesc;
96
	int			 wfdesc;
97
	unsigned char		*rbuf;
98
	size_t			 rbuf_max;
99
	size_t			 rbuf_offset;
100
	size_t			 rbuf_len;
101
	struct ifreq		 ifr;
102
	int			 noifmedia;
103
	int			 errors;
104
	int			 dead;
105
	uint16_t		 index;
106
107
	int			 ipv6; /* Has any IPv6 address. */
108
	int			 gipv6; /* Has global IPv6 address. */
109
	struct in6_addr		 linklocal; /* IPv6 link-local address. */
110
111
	TAILQ_ENTRY(interface_info) entry;
112
};
113
TAILQ_HEAD(intfq, interface_info);
114
115
struct timeout {
116
	struct timeout	*next;
117
	time_t		 when;
118
	void		 (*func)(void *);
119
	void		*what;
120
};
121
122
struct protocol {
123
	struct protocol	*next;
124
	int fd;
125
	void (*handler)(struct protocol *);
126
	void *local;
127
};
128
129
struct server_list {
130
	struct interface_info *intf;
131
	struct sockaddr_storage to;
132
	int fd;
133
	int siteglobaladdr;
134
	TAILQ_ENTRY(server_list) entry;
135
};
136
TAILQ_HEAD(serverq, server_list);
137
138
/* bpf.c */
139
int if_register_bpf(struct interface_info *);
140
void if_register_send(struct interface_info *);
141
void if_register_receive(struct interface_info *);
142
ssize_t send_packet(struct interface_info *,
143
    void *, size_t, struct packet_ctx *);
144
ssize_t receive_packet(struct interface_info *, unsigned char *, size_t,
145
    struct packet_ctx *);
146
147
/* dispatch.c */
148
extern void (*bootp_packet_handler)(struct interface_info *,
149
    void *, size_t, struct packet_ctx *);
150
void setup_iflist(void);
151
struct interface_info *iflist_getbyname(const char *);
152
struct interface_info *iflist_getbyindex(unsigned int);
153
struct interface_info *iflist_getbyaddr6(struct in6_addr *);
154
int if_hasaddress(struct interface_info *);
155
struct interface_info *register_interface(const char *,
156
    void (*)(struct protocol *));
157
void dispatch(void);
158
void got_one(struct protocol *);
159
void add_protocol(char *, int, void (*)(struct protocol *), void *);
160
void remove_protocol(struct protocol *);
161
162
/* packet.c */
163
void assemble_hw_header(unsigned char *, int *, struct packet_ctx *);
164
void assemble_udp_ip6_header(unsigned char *, int *, struct packet_ctx *,
165
    unsigned char *, int);
166
ssize_t decode_hw_header(unsigned char *, int, struct packet_ctx *);
167
ssize_t decode_udp_ip6_header(unsigned char *, int, struct packet_ctx *,
168
    size_t);
169
170
/* dhcrelay6.c */
171
const char *v6addr2str(struct in6_addr *);
172
173
extern struct intfq intflist;
174
extern struct serverq svlist;
175
extern time_t cur_time;
176
177
static inline struct sockaddr_in6 *
178
ss2sin6(struct sockaddr_storage *ss)
179
{
180
	return ((struct sockaddr_in6 *)ss);
181
}
182
183
#endif /* _DHCPD_H_ */