blob: eb211ea0f14517994c93e9c91a2ac3e0d35bf066 [file] [log] [blame]
Denys Vlasenko9ba75042011-11-07 15:55:39 +01001/* vi: set sw=4 ts=4: */
2/*
3 * Copyright (C) 2011 Denys Vlasenko.
4 *
5 * Licensed under GPLv2, see file LICENSE in this source tree.
6 */
7#ifndef UDHCP_D6_COMMON_H
8#define UDHCP_D6_COMMON_H 1
9
10#include <netinet/ip6.h>
11
12PUSH_AND_SET_FUNCTION_VISIBILITY_TO_HIDDEN
13
14
15/*** DHCPv6 packet ***/
16
17/* DHCPv6 protocol. See RFC 3315 */
18#define D6_MSG_SOLICIT 1
19#define D6_MSG_ADVERTISE 2
20#define D6_MSG_REQUEST 3
21#define D6_MSG_CONFIRM 4
22#define D6_MSG_RENEW 5
23#define D6_MSG_REBIND 6
24#define D6_MSG_REPLY 7
25#define D6_MSG_RELEASE 8
26#define D6_MSG_DECLINE 9
27#define D6_MSG_RECONFIGURE 10
28#define D6_MSG_INFORMATION_REQUEST 11
29#define D6_MSG_RELAY_FORW 12
30#define D6_MSG_RELAY_REPL 13
31
32struct d6_packet {
33 union {
34 uint8_t d6_msg_type;
35 uint32_t d6_xid32;
36 } d6_u;
37 uint8_t d6_options[576 - sizeof(struct iphdr) - sizeof(struct udphdr) - 4
38 + CONFIG_UDHCPC_SLACK_FOR_BUGGY_SERVERS];
39} PACKED;
40#define d6_msg_type d6_u.d6_msg_type
41#define d6_xid32 d6_u.d6_xid32
42
43struct ip6_udp_d6_packet {
44 struct ip6_hdr ip6;
45 struct udphdr udp;
46 struct d6_packet data;
47} PACKED;
48
49struct udp_d6_packet {
50 struct udphdr udp;
51 struct d6_packet data;
52} PACKED;
53
54/*** Options ***/
55
56struct d6_option {
Denys Vlasenko9ba75042011-11-07 15:55:39 +010057 uint8_t code_hi;
Denys Vlasenko68c5b282011-11-07 16:21:24 +010058 uint8_t code;
Denys Vlasenko9ba75042011-11-07 15:55:39 +010059 uint8_t len_hi;
Denys Vlasenko68c5b282011-11-07 16:21:24 +010060 uint8_t len;
Denys Vlasenko9ba75042011-11-07 15:55:39 +010061 uint8_t data[1];
62} PACKED;
63
64#define D6_OPT_CLIENTID 1
65#define D6_OPT_SERVERID 2
66#define D6_OPT_IA_NA 3
67#define D6_OPT_IA_TA 4
68#define D6_OPT_IAADDR 5
69#define D6_OPT_ORO 6
70#define D6_OPT_PREFERENCE 7
71#define D6_OPT_ELAPSED_TIME 8
72#define D6_OPT_RELAY_MSG 9
73#define D6_OPT_AUTH 11
74#define D6_OPT_UNICAST 12
75#define D6_OPT_STATUS_CODE 13
76#define D6_OPT_RAPID_COMMIT 14
77#define D6_OPT_USER_CLASS 15
78#define D6_OPT_VENDOR_CLASS 16
79#define D6_OPT_VENDOR_OPTS 17
80#define D6_OPT_INTERFACE_ID 18
81#define D6_OPT_RECONF_MSG 19
82#define D6_OPT_RECONF_ACCEPT 20
83
Denys Vlasenkoa092a892011-11-16 20:17:12 +010084#define D6_OPT_IA_PD 25
85#define D6_OPT_IAPREFIX 26
86
Denys Vlasenko9ba75042011-11-07 15:55:39 +010087/*** Other shared functions ***/
88
89struct client6_data_t {
90 struct d6_option *server_id;
91 struct d6_option *ia_na;
Denys Vlasenkoa092a892011-11-16 20:17:12 +010092 char **env_ptr;
93 unsigned env_idx;
Denys Vlasenko9ba75042011-11-07 15:55:39 +010094};
95
96#define client6_data (*(struct client6_data_t*)(&bb_common_bufsiz1[COMMON_BUFSIZE - sizeof(struct client6_data_t)]))
97
98int FAST_FUNC d6_listen_socket(int port, const char *inf);
99
100int FAST_FUNC d6_recv_kernel_packet(
101 struct in6_addr *peer_ipv6,
102 struct d6_packet *packet, int fd
103);
104
105int FAST_FUNC d6_send_raw_packet(
106 struct d6_packet *d6_pkt, unsigned d6_pkt_size,
107 struct in6_addr *src_ipv6, int source_port,
108 struct in6_addr *dst_ipv6, int dest_port, const uint8_t *dest_arp,
109 int ifindex
110);
111
112int FAST_FUNC d6_send_kernel_packet(
113 struct d6_packet *d6_pkt, unsigned d6_pkt_size,
114 struct in6_addr *src_ipv6, int source_port,
115 struct in6_addr *dst_ipv6, int dest_port
116);
117
Denys Vlasenko8cab6672012-04-20 14:48:00 +0200118#if defined CONFIG_UDHCP_DEBUG && CONFIG_UDHCP_DEBUG >= 2
Denys Vlasenko9ba75042011-11-07 15:55:39 +0100119void FAST_FUNC d6_dump_packet(struct d6_packet *packet);
Denys Vlasenko8cab6672012-04-20 14:48:00 +0200120#else
121# define d6_dump_packet(packet) ((void)0)
122#endif
Denys Vlasenko9ba75042011-11-07 15:55:39 +0100123
124
125POP_SAVED_FUNCTION_VISIBILITY
126
127#endif