libosmo-netif: include/osmocom/netif/icmpv6.h Source File

libosmo-netif 1.7.0.15-fe2d Osmocom network interface library

icmpv6.h
1#pragma once
2
3#include <stdint.h>
4#include <stdbool.h>
5#include <netinet/in.h>
6
7#include <osmocom/core/msgb.h>
8#include <osmocom/core/endian.h>
9
10#define ICMPv6_OPT_TYPE_PREFIX_INFO 0x03
11
12 struct osmo_icmpv6_hdr {
13 uint8_t type;
14 uint8_t code;
15 uint16_t csum;
16} __attribute__ ((packed));
17
18 struct osmo_icmpv6_echo_hdr {
19 struct osmo_icmpv6_hdr hdr;
20 uint16_t ident; /* Identifier */
21 uint16_t seq; /* Sequence number */
22 uint8_t data[0]; /* Data */
23} __attribute__ ((packed));
24
25/* RFC4861 Section 4.1 */
26 struct osmo_icmpv6_rsol_hdr {
27 struct osmo_icmpv6_hdr hdr;
28 uint32_t reserved;
29 uint8_t options[0];
30} __attribute__ ((packed));
31
32/* RFC4861 Section 4.2 */
33 struct osmo_icmpv6_radv_hdr {
34 struct osmo_icmpv6_hdr hdr;
35 uint8_t cur_ho_limit;
36#if OSMO_IS_LITTLE_ENDIAN
37 uint8_t res:6,
38 m:1,
39 o:1;
40#elif OSMO_IS_BIG_ENDIAN
41/* auto-generated from the little endian part above (libosmocore/contrib/struct_endianness.py) */
42 uint8_t o:1, m:1, res:6;
43#endif
44 uint16_t router_lifetime;
45 uint32_t reachable_time;
46 uint32_t retrans_timer;
47 uint8_t options[0];
48} __attribute__ ((packed));
49
50
51/* RFC4861 Section 4.6 */
52 struct osmo_icmpv6_opt_hdr {
53 uint8_t type;
54 /* length in units of 8 octets, including type+len! */
55 uint8_t len;
56 uint8_t data[0];
57} __attribute__ ((packed));
58
59/* RFC4861 Section 4.6.2 */
60 struct osmo_icmpv6_opt_prefix {
61 struct osmo_icmpv6_opt_hdr hdr;
62 uint8_t prefix_len;
63#if OSMO_IS_LITTLE_ENDIAN
64 uint8_t res:6,
65 a:1,
66 l:1;
67#elif OSMO_IS_BIG_ENDIAN
68/* auto-generated from the little endian part above (libosmocore/contrib/struct_endianness.py) */
69 uint8_t l:1, a:1, res:6;
70#endif
71 uint32_t valid_lifetime;
72 uint32_t preferred_lifetime;
73 uint32_t res2;
74 uint8_t prefix[16];
75} __attribute__ ((packed));
76
77/* RFC4861 Section 4.6.4 */
78 struct osmo_icmpv6_opt_mtu {
79 struct osmo_icmpv6_opt_hdr hdr;
80 uint16_t reserved;
81 uint32_t mtu;
82} __attribute__ ((packed));
83
84uint16_t osmo_icmpv6_prepend_ip6hdr(struct msgb *msg, const struct in6_addr *saddr,
85 const struct in6_addr *daddr);
86
87struct msgb *osmo_icmpv6_construct_rs(const struct in6_addr *saddr);
88struct msgb *osmo_icmpv6_construct_ra(const struct in6_addr *saddr,
89 const struct in6_addr *daddr,
90 const struct in6_addr *prefix,
91 uint32_t mtu);
92
93bool osmo_icmpv6_validate_router_solicit(const uint8_t *pack, unsigned len);
94struct osmo_icmpv6_radv_hdr *osmo_icmpv6_validate_router_adv(const uint8_t *pack, unsigned len);
95
96#define foreach_icmpv6_opt(icmpv6_pkt, icmpv6_len, opt_hdr) \
97 for (opt_hdr = (struct osmo_icmpv6_opt_hdr *)(icmpv6_pkt)->options; \
98 (uint8_t *)(opt_hdr) + sizeof(struct osmo_icmpv6_opt_hdr) <= (((uint8_t *)(icmpv6_pkt)) + (icmpv6_len)); \
99 opt_hdr = (struct osmo_icmpv6_opt_hdr *)((uint8_t *)(opt_hdr) + (opt_hdr)->len) \
100 )
101
102/* RFC3307 link-local scope multicast address */
103extern const struct in6_addr osmo_icmpv6_all_router_mcast_addr;
104
105extern const uint8_t osmo_icmpv6_solicited_node_mcast_addr_prefix[13];
osmo_icmpv6_echo_hdr
Definition: icmpv6.h:18
osmo_icmpv6_hdr
Definition: icmpv6.h:12
osmo_icmpv6_opt_hdr
Definition: icmpv6.h:52
osmo_icmpv6_opt_mtu
Definition: icmpv6.h:78
osmo_icmpv6_opt_prefix
Definition: icmpv6.h:60
osmo_icmpv6_radv_hdr
Definition: icmpv6.h:33
osmo_icmpv6_rsol_hdr
Definition: icmpv6.h:26