]> git.proxmox.com Git - mirror_ovs.git/blob - lib/packets.h
flow: Fix using pointer to member of packed struct icmp6_hdr.
[mirror_ovs.git] / lib / packets.h
1 /*
2 * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Nicira, Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #ifndef PACKETS_H
18 #define PACKETS_H 1
19
20 #include <inttypes.h>
21 #include <sys/types.h>
22 #include <stdint.h>
23 #include <string.h>
24 #include "compiler.h"
25 #include "openvswitch/geneve.h"
26 #include "openvswitch/packets.h"
27 #include "openvswitch/types.h"
28 #include "openvswitch/nsh.h"
29 #include "odp-netlink.h"
30 #include "random.h"
31 #include "hash.h"
32 #include "tun-metadata.h"
33 #include "unaligned.h"
34 #include "util.h"
35 #include "timeval.h"
36
37 struct dp_packet;
38 struct conn;
39 struct ds;
40
41 /* Purely internal to OVS userspace. These flags should never be exposed to
42 * the outside world and so aren't included in the flags mask. */
43
44 /* Tunnel information is in userspace datapath format. */
45 #define FLOW_TNL_F_UDPIF (1 << 4)
46
47 static inline bool ipv6_addr_is_set(const struct in6_addr *addr);
48
49 static inline bool
50 flow_tnl_dst_is_set(const struct flow_tnl *tnl)
51 {
52 return tnl->ip_dst || ipv6_addr_is_set(&tnl->ipv6_dst);
53 }
54
55 struct in6_addr flow_tnl_dst(const struct flow_tnl *tnl);
56 struct in6_addr flow_tnl_src(const struct flow_tnl *tnl);
57
58 /* Returns an offset to 'src' covering all the meaningful fields in 'src'. */
59 static inline size_t
60 flow_tnl_size(const struct flow_tnl *src)
61 {
62 if (!flow_tnl_dst_is_set(src)) {
63 /* Covers ip_dst and ipv6_dst only. */
64 return offsetof(struct flow_tnl, ip_src);
65 }
66 if (src->flags & FLOW_TNL_F_UDPIF) {
67 /* Datapath format, cover all options we have. */
68 return offsetof(struct flow_tnl, metadata.opts)
69 + src->metadata.present.len;
70 }
71 if (!src->metadata.present.map) {
72 /* No TLVs, opts is irrelevant. */
73 return offsetof(struct flow_tnl, metadata.opts);
74 }
75 /* Have decoded TLVs, opts is relevant. */
76 return sizeof *src;
77 }
78
79 /* Copy flow_tnl, but avoid copying unused portions of tun_metadata. Unused
80 * data in 'dst' is NOT cleared, so this must not be used in cases where the
81 * uninitialized portion may be hashed over. */
82 static inline void
83 flow_tnl_copy__(struct flow_tnl *dst, const struct flow_tnl *src)
84 {
85 memcpy(dst, src, flow_tnl_size(src));
86 }
87
88 static inline bool
89 flow_tnl_equal(const struct flow_tnl *a, const struct flow_tnl *b)
90 {
91 size_t a_size = flow_tnl_size(a);
92
93 return a_size == flow_tnl_size(b) && !memcmp(a, b, a_size);
94 }
95
96 /* Datapath packet metadata */
97 struct pkt_metadata {
98 PADDED_MEMBERS_CACHELINE_MARKER(CACHE_LINE_SIZE, cacheline0,
99 uint32_t recirc_id; /* Recirculation id carried with the
100 recirculating packets. 0 for packets
101 received from the wire. */
102 uint32_t dp_hash; /* hash value computed by the recirculation
103 action. */
104 uint32_t skb_priority; /* Packet priority for QoS. */
105 uint32_t pkt_mark; /* Packet mark. */
106 uint8_t ct_state; /* Connection state. */
107 bool ct_orig_tuple_ipv6;
108 uint16_t ct_zone; /* Connection zone. */
109 uint32_t ct_mark; /* Connection mark. */
110 ovs_u128 ct_label; /* Connection label. */
111 union flow_in_port in_port; /* Input port. */
112 struct conn *conn; /* Cached conntrack connection. */
113 bool reply; /* True if reply direction. */
114 bool icmp_related; /* True if ICMP related. */
115 );
116
117 PADDED_MEMBERS_CACHELINE_MARKER(CACHE_LINE_SIZE, cacheline1,
118 union { /* Populated only for non-zero 'ct_state'. */
119 struct ovs_key_ct_tuple_ipv4 ipv4;
120 struct ovs_key_ct_tuple_ipv6 ipv6; /* Used only if */
121 } ct_orig_tuple; /* 'ct_orig_tuple_ipv6' is set */
122 );
123
124 PADDED_MEMBERS_CACHELINE_MARKER(CACHE_LINE_SIZE, cacheline2,
125 struct flow_tnl tunnel; /* Encapsulating tunnel parameters. Note that
126 * if 'ip_dst' == 0, the rest of the fields may
127 * be uninitialized. */
128 );
129 };
130
131 BUILD_ASSERT_DECL(offsetof(struct pkt_metadata, cacheline0) == 0);
132 BUILD_ASSERT_DECL(offsetof(struct pkt_metadata, cacheline1) ==
133 CACHE_LINE_SIZE);
134 BUILD_ASSERT_DECL(offsetof(struct pkt_metadata, cacheline2) ==
135 2 * CACHE_LINE_SIZE);
136
137 static inline void
138 pkt_metadata_init_tnl(struct pkt_metadata *md)
139 {
140 /* Zero up through the tunnel metadata options. The length and table
141 * are before this and as long as they are empty, the options won't
142 * be looked at. */
143 memset(md, 0, offsetof(struct pkt_metadata, tunnel.metadata.opts));
144 }
145
146 static inline void
147 pkt_metadata_init_conn(struct pkt_metadata *md)
148 {
149 md->conn = NULL;
150 }
151
152 static inline void
153 pkt_metadata_init(struct pkt_metadata *md, odp_port_t port)
154 {
155 /* This is called for every packet in userspace datapath and affects
156 * performance if all the metadata is initialized. Hence, fields should
157 * only be zeroed out when necessary.
158 *
159 * Initialize only till ct_state. Once the ct_state is zeroed out rest
160 * of ct fields will not be looked at unless ct_state != 0.
161 */
162 memset(md, 0, offsetof(struct pkt_metadata, ct_orig_tuple_ipv6));
163
164 /* It can be expensive to zero out all of the tunnel metadata. However,
165 * we can just zero out ip_dst and the rest of the data will never be
166 * looked at. */
167 md->tunnel.ip_dst = 0;
168 md->tunnel.ipv6_dst = in6addr_any;
169 md->in_port.odp_port = port;
170 md->conn = NULL;
171 }
172
173 /* This function prefetches the cachelines touched by pkt_metadata_init()
174 * and pkt_metadata_init_tnl(). For performance reasons the two functions
175 * should be kept in sync. */
176 static inline void
177 pkt_metadata_prefetch_init(struct pkt_metadata *md)
178 {
179 /* Prefetch cacheline0 as members till ct_state and odp_port will
180 * be initialized later in pkt_metadata_init(). */
181 OVS_PREFETCH(md->cacheline0);
182
183 /* Prefetch cacheline1 as members of this cacheline will be zeroed out
184 * in pkt_metadata_init_tnl(). */
185 OVS_PREFETCH(md->cacheline1);
186
187 /* Prefetch cachline2 as ip_dst & ipv6_dst fields will be initialized. */
188 OVS_PREFETCH(md->cacheline2);
189 }
190
191 bool dpid_from_string(const char *s, uint64_t *dpidp);
192
193 #define ETH_ADDR_LEN 6
194
195 static const struct eth_addr eth_addr_broadcast OVS_UNUSED
196 = ETH_ADDR_C(ff,ff,ff,ff,ff,ff);
197
198 static const struct eth_addr eth_addr_exact OVS_UNUSED
199 = ETH_ADDR_C(ff,ff,ff,ff,ff,ff);
200
201 static const struct eth_addr eth_addr_zero OVS_UNUSED
202 = ETH_ADDR_C(00,00,00,00,00,00);
203 static const struct eth_addr64 eth_addr64_zero OVS_UNUSED
204 = ETH_ADDR64_C(00,00,00,00,00,00,00,00);
205
206 static const struct eth_addr eth_addr_stp OVS_UNUSED
207 = ETH_ADDR_C(01,80,c2,00,00,00);
208
209 static const struct eth_addr eth_addr_lacp OVS_UNUSED
210 = ETH_ADDR_C(01,80,c2,00,00,02);
211
212 static const struct eth_addr eth_addr_bfd OVS_UNUSED
213 = ETH_ADDR_C(00,23,20,00,00,01);
214
215 static inline bool eth_addr_is_broadcast(const struct eth_addr a)
216 {
217 return (a.be16[0] & a.be16[1] & a.be16[2]) == htons(0xffff);
218 }
219
220 static inline bool eth_addr_is_multicast(const struct eth_addr a)
221 {
222 return a.ea[0] & 1;
223 }
224
225 static inline bool eth_addr_is_local(const struct eth_addr a)
226 {
227 /* Local if it is either a locally administered address or a Nicira random
228 * address. */
229 return a.ea[0] & 2
230 || (a.be16[0] == htons(0x0023)
231 && (a.be16[1] & htons(0xff80)) == htons(0x2080));
232 }
233 static inline bool eth_addr_is_zero(const struct eth_addr a)
234 {
235 return !(a.be16[0] | a.be16[1] | a.be16[2]);
236 }
237 static inline bool eth_addr64_is_zero(const struct eth_addr64 a)
238 {
239 return !(a.be16[0] | a.be16[1] | a.be16[2] | a.be16[3]);
240 }
241
242 static inline int eth_mask_is_exact(const struct eth_addr a)
243 {
244 return (a.be16[0] & a.be16[1] & a.be16[2]) == htons(0xffff);
245 }
246
247 static inline int eth_addr_compare_3way(const struct eth_addr a,
248 const struct eth_addr b)
249 {
250 return memcmp(&a, &b, sizeof a);
251 }
252 static inline int eth_addr64_compare_3way(const struct eth_addr64 a,
253 const struct eth_addr64 b)
254 {
255 return memcmp(&a, &b, sizeof a);
256 }
257
258 static inline bool eth_addr_equals(const struct eth_addr a,
259 const struct eth_addr b)
260 {
261 return !eth_addr_compare_3way(a, b);
262 }
263 static inline bool eth_addr64_equals(const struct eth_addr64 a,
264 const struct eth_addr64 b)
265 {
266 return !eth_addr64_compare_3way(a, b);
267 }
268
269 static inline bool eth_addr_equal_except(const struct eth_addr a,
270 const struct eth_addr b,
271 const struct eth_addr mask)
272 {
273 return !(((a.be16[0] ^ b.be16[0]) & mask.be16[0])
274 || ((a.be16[1] ^ b.be16[1]) & mask.be16[1])
275 || ((a.be16[2] ^ b.be16[2]) & mask.be16[2]));
276 }
277
278 static inline uint64_t eth_addr_to_uint64(const struct eth_addr ea)
279 {
280 return (((uint64_t) ntohs(ea.be16[0]) << 32)
281 | ((uint64_t) ntohs(ea.be16[1]) << 16)
282 | ntohs(ea.be16[2]));
283 }
284
285 static inline uint64_t eth_addr_vlan_to_uint64(const struct eth_addr ea,
286 uint16_t vlan)
287 {
288 return (((uint64_t)vlan << 48) | eth_addr_to_uint64(ea));
289 }
290
291 static inline void eth_addr_from_uint64(uint64_t x, struct eth_addr *ea)
292 {
293 ea->be16[0] = htons(x >> 32);
294 ea->be16[1] = htons((x & 0xFFFF0000) >> 16);
295 ea->be16[2] = htons(x & 0xFFFF);
296 }
297
298 static inline struct eth_addr eth_addr_invert(const struct eth_addr src)
299 {
300 struct eth_addr dst;
301
302 for (int i = 0; i < ARRAY_SIZE(src.be16); i++) {
303 dst.be16[i] = ~src.be16[i];
304 }
305
306 return dst;
307 }
308
309 static inline void eth_addr_mark_random(struct eth_addr *ea)
310 {
311 ea->ea[0] &= ~1; /* Unicast. */
312 ea->ea[0] |= 2; /* Private. */
313 }
314
315 static inline void eth_addr_random(struct eth_addr *ea)
316 {
317 random_bytes((uint8_t *)ea, sizeof *ea);
318 eth_addr_mark_random(ea);
319 }
320
321 static inline void eth_addr_nicira_random(struct eth_addr *ea)
322 {
323 eth_addr_random(ea);
324
325 /* Set the OUI to the Nicira one. */
326 ea->ea[0] = 0x00;
327 ea->ea[1] = 0x23;
328 ea->ea[2] = 0x20;
329
330 /* Set the top bit to indicate random Nicira address. */
331 ea->ea[3] |= 0x80;
332 }
333 static inline uint32_t hash_mac(const struct eth_addr ea,
334 const uint16_t vlan, const uint32_t basis)
335 {
336 return hash_uint64_basis(eth_addr_vlan_to_uint64(ea, vlan), basis);
337 }
338
339 bool eth_addr_is_reserved(const struct eth_addr);
340 bool eth_addr_from_string(const char *, struct eth_addr *);
341
342 void compose_rarp(struct dp_packet *, const struct eth_addr);
343
344 void eth_push_vlan(struct dp_packet *, ovs_be16 tpid, ovs_be16 tci);
345 void eth_pop_vlan(struct dp_packet *);
346
347 const char *eth_from_hex(const char *hex, struct dp_packet **packetp);
348 void eth_format_masked(const struct eth_addr ea,
349 const struct eth_addr *mask, struct ds *s);
350
351 void set_mpls_lse(struct dp_packet *, ovs_be32 label);
352 void push_mpls(struct dp_packet *packet, ovs_be16 ethtype, ovs_be32 lse);
353 void pop_mpls(struct dp_packet *, ovs_be16 ethtype);
354
355 void set_mpls_lse_ttl(ovs_be32 *lse, uint8_t ttl);
356 void set_mpls_lse_tc(ovs_be32 *lse, uint8_t tc);
357 void set_mpls_lse_label(ovs_be32 *lse, ovs_be32 label);
358 void set_mpls_lse_bos(ovs_be32 *lse, uint8_t bos);
359 ovs_be32 set_mpls_lse_values(uint8_t ttl, uint8_t tc, uint8_t bos,
360 ovs_be32 label);
361
362 /* Example:
363 *
364 * struct eth_addr mac;
365 * [...]
366 * printf("The Ethernet address is "ETH_ADDR_FMT"\n", ETH_ADDR_ARGS(mac));
367 *
368 */
369 #define ETH_ADDR_FMT \
370 "%02"PRIx8":%02"PRIx8":%02"PRIx8":%02"PRIx8":%02"PRIx8":%02"PRIx8
371 #define ETH_ADDR_ARGS(EA) ETH_ADDR_BYTES_ARGS((EA).ea)
372 #define ETH_ADDR_BYTES_ARGS(EAB) \
373 (EAB)[0], (EAB)[1], (EAB)[2], (EAB)[3], (EAB)[4], (EAB)[5]
374 #define ETH_ADDR_STRLEN 17
375
376 /* Example:
377 *
378 * struct eth_addr64 eui64;
379 * [...]
380 * printf("The EUI-64 address is "ETH_ADDR64_FMT"\n", ETH_ADDR64_ARGS(mac));
381 *
382 */
383 #define ETH_ADDR64_FMT \
384 "%02"PRIx8":%02"PRIx8":%02"PRIx8":%02"PRIx8":" \
385 "%02"PRIx8":%02"PRIx8":%02"PRIx8":%02"PRIx8
386 #define ETH_ADDR64_ARGS(EA) ETH_ADDR64_BYTES_ARGS((EA).ea64)
387 #define ETH_ADDR64_BYTES_ARGS(EAB) \
388 (EAB)[0], (EAB)[1], (EAB)[2], (EAB)[3], \
389 (EAB)[4], (EAB)[5], (EAB)[6], (EAB)[7]
390 #define ETH_ADDR64_STRLEN 23
391
392 /* Example:
393 *
394 * char *string = "1 00:11:22:33:44:55 2";
395 * struct eth_addr mac;
396 * int a, b;
397 *
398 * if (ovs_scan(string, "%d"ETH_ADDR_SCAN_FMT"%d",
399 * &a, ETH_ADDR_SCAN_ARGS(mac), &b)) {
400 * ...
401 * }
402 */
403 #define ETH_ADDR_SCAN_FMT "%"SCNx8":%"SCNx8":%"SCNx8":%"SCNx8":%"SCNx8":%"SCNx8
404 #define ETH_ADDR_SCAN_ARGS(EA) \
405 &(EA).ea[0], &(EA).ea[1], &(EA).ea[2], &(EA).ea[3], &(EA).ea[4], &(EA).ea[5]
406
407 #define ETH_TYPE_IP 0x0800
408 #define ETH_TYPE_ARP 0x0806
409 #define ETH_TYPE_TEB 0x6558
410 #define ETH_TYPE_VLAN_8021Q 0x8100
411 #define ETH_TYPE_VLAN ETH_TYPE_VLAN_8021Q
412 #define ETH_TYPE_VLAN_8021AD 0x88a8
413 #define ETH_TYPE_IPV6 0x86dd
414 #define ETH_TYPE_LACP 0x8809
415 #define ETH_TYPE_RARP 0x8035
416 #define ETH_TYPE_MPLS 0x8847
417 #define ETH_TYPE_MPLS_MCAST 0x8848
418 #define ETH_TYPE_NSH 0x894f
419 #define ETH_TYPE_ERSPAN1 0x88be /* version 1 type II */
420 #define ETH_TYPE_ERSPAN2 0x22eb /* version 2 type III */
421
422 static inline bool eth_type_mpls(ovs_be16 eth_type)
423 {
424 return eth_type == htons(ETH_TYPE_MPLS) ||
425 eth_type == htons(ETH_TYPE_MPLS_MCAST);
426 }
427
428 static inline bool eth_type_vlan(ovs_be16 eth_type)
429 {
430 return eth_type == htons(ETH_TYPE_VLAN_8021Q) ||
431 eth_type == htons(ETH_TYPE_VLAN_8021AD);
432 }
433
434
435 /* Minimum value for an Ethernet type. Values below this are IEEE 802.2 frame
436 * lengths. */
437 #define ETH_TYPE_MIN 0x600
438
439 #define ETH_HEADER_LEN 14
440 #define ETH_PAYLOAD_MIN 46
441 #define ETH_PAYLOAD_MAX 1500
442 #define ETH_TOTAL_MIN (ETH_HEADER_LEN + ETH_PAYLOAD_MIN)
443 #define ETH_TOTAL_MAX (ETH_HEADER_LEN + ETH_PAYLOAD_MAX)
444 #define ETH_VLAN_TOTAL_MAX (ETH_HEADER_LEN + VLAN_HEADER_LEN + ETH_PAYLOAD_MAX)
445 struct eth_header {
446 struct eth_addr eth_dst;
447 struct eth_addr eth_src;
448 ovs_be16 eth_type;
449 };
450 BUILD_ASSERT_DECL(ETH_HEADER_LEN == sizeof(struct eth_header));
451
452 void push_eth(struct dp_packet *packet, const struct eth_addr *dst,
453 const struct eth_addr *src);
454 void pop_eth(struct dp_packet *packet);
455
456 void push_nsh(struct dp_packet *packet, const struct nsh_hdr *nsh_hdr_src);
457 bool pop_nsh(struct dp_packet *packet);
458
459 #define LLC_DSAP_SNAP 0xaa
460 #define LLC_SSAP_SNAP 0xaa
461 #define LLC_CNTL_SNAP 3
462
463 #define LLC_HEADER_LEN 3
464 struct llc_header {
465 uint8_t llc_dsap;
466 uint8_t llc_ssap;
467 uint8_t llc_cntl;
468 };
469 BUILD_ASSERT_DECL(LLC_HEADER_LEN == sizeof(struct llc_header));
470
471 /* LLC field values used for STP frames. */
472 #define STP_LLC_SSAP 0x42
473 #define STP_LLC_DSAP 0x42
474 #define STP_LLC_CNTL 0x03
475
476 #define SNAP_ORG_ETHERNET "\0\0" /* The compiler adds a null byte, so
477 sizeof(SNAP_ORG_ETHERNET) == 3. */
478 #define SNAP_HEADER_LEN 5
479 OVS_PACKED(
480 struct snap_header {
481 uint8_t snap_org[3];
482 ovs_be16 snap_type;
483 });
484 BUILD_ASSERT_DECL(SNAP_HEADER_LEN == sizeof(struct snap_header));
485
486 #define LLC_SNAP_HEADER_LEN (LLC_HEADER_LEN + SNAP_HEADER_LEN)
487 OVS_PACKED(
488 struct llc_snap_header {
489 struct llc_header llc;
490 struct snap_header snap;
491 });
492 BUILD_ASSERT_DECL(LLC_SNAP_HEADER_LEN == sizeof(struct llc_snap_header));
493
494 #define VLAN_VID_MASK 0x0fff
495 #define VLAN_VID_SHIFT 0
496
497 #define VLAN_PCP_MASK 0xe000
498 #define VLAN_PCP_SHIFT 13
499
500 #define VLAN_CFI 0x1000
501 #define VLAN_CFI_SHIFT 12
502
503 /* Given the vlan_tci field from an 802.1Q header, in network byte order,
504 * returns the VLAN ID in host byte order. */
505 static inline uint16_t
506 vlan_tci_to_vid(ovs_be16 vlan_tci)
507 {
508 return (ntohs(vlan_tci) & VLAN_VID_MASK) >> VLAN_VID_SHIFT;
509 }
510
511 /* Given the vlan_tci field from an 802.1Q header, in network byte order,
512 * returns the priority code point (PCP) in host byte order. */
513 static inline int
514 vlan_tci_to_pcp(ovs_be16 vlan_tci)
515 {
516 return (ntohs(vlan_tci) & VLAN_PCP_MASK) >> VLAN_PCP_SHIFT;
517 }
518
519 /* Given the vlan_tci field from an 802.1Q header, in network byte order,
520 * returns the Canonical Format Indicator (CFI). */
521 static inline int
522 vlan_tci_to_cfi(ovs_be16 vlan_tci)
523 {
524 return (vlan_tci & htons(VLAN_CFI)) != 0;
525 }
526
527 #define VLAN_HEADER_LEN 4
528 struct vlan_header {
529 ovs_be16 vlan_tci; /* Lowest 12 bits are VLAN ID. */
530 ovs_be16 vlan_next_type;
531 };
532 BUILD_ASSERT_DECL(VLAN_HEADER_LEN == sizeof(struct vlan_header));
533
534 #define VLAN_ETH_HEADER_LEN (ETH_HEADER_LEN + VLAN_HEADER_LEN)
535 struct vlan_eth_header {
536 struct eth_addr veth_dst;
537 struct eth_addr veth_src;
538 ovs_be16 veth_type; /* Always htons(ETH_TYPE_VLAN). */
539 ovs_be16 veth_tci; /* Lowest 12 bits are VLAN ID. */
540 ovs_be16 veth_next_type;
541 };
542 BUILD_ASSERT_DECL(VLAN_ETH_HEADER_LEN == sizeof(struct vlan_eth_header));
543
544 /* MPLS related definitions */
545 #define MPLS_TTL_MASK 0x000000ff
546 #define MPLS_TTL_SHIFT 0
547
548 #define MPLS_BOS_MASK 0x00000100
549 #define MPLS_BOS_SHIFT 8
550
551 #define MPLS_TC_MASK 0x00000e00
552 #define MPLS_TC_SHIFT 9
553
554 #define MPLS_LABEL_MASK 0xfffff000
555 #define MPLS_LABEL_SHIFT 12
556
557 #define MPLS_HLEN 4
558
559 struct mpls_hdr {
560 ovs_16aligned_be32 mpls_lse;
561 };
562 BUILD_ASSERT_DECL(MPLS_HLEN == sizeof(struct mpls_hdr));
563
564 /* Given a mpls label stack entry in network byte order
565 * return mpls label in host byte order */
566 static inline uint32_t
567 mpls_lse_to_label(ovs_be32 mpls_lse)
568 {
569 return (ntohl(mpls_lse) & MPLS_LABEL_MASK) >> MPLS_LABEL_SHIFT;
570 }
571
572 /* Given a mpls label stack entry in network byte order
573 * return mpls tc */
574 static inline uint8_t
575 mpls_lse_to_tc(ovs_be32 mpls_lse)
576 {
577 return (ntohl(mpls_lse) & MPLS_TC_MASK) >> MPLS_TC_SHIFT;
578 }
579
580 /* Given a mpls label stack entry in network byte order
581 * return mpls ttl */
582 static inline uint8_t
583 mpls_lse_to_ttl(ovs_be32 mpls_lse)
584 {
585 return (ntohl(mpls_lse) & MPLS_TTL_MASK) >> MPLS_TTL_SHIFT;
586 }
587
588 /* Set label in mpls lse. */
589 static inline void
590 flow_set_mpls_lse_label(ovs_be32 *mpls_lse, uint32_t label)
591 {
592 *mpls_lse &= ~htonl(MPLS_LABEL_MASK);
593 *mpls_lse |= htonl(label << MPLS_LABEL_SHIFT);
594 }
595
596 /* Set TC in mpls lse. */
597 static inline void
598 flow_set_mpls_lse_tc(ovs_be32 *mpls_lse, uint8_t tc)
599 {
600 *mpls_lse &= ~htonl(MPLS_TC_MASK);
601 *mpls_lse |= htonl((tc & 0x7) << MPLS_TC_SHIFT);
602 }
603
604 /* Set BOS in mpls lse. */
605 static inline void
606 flow_set_mpls_lse_bos(ovs_be32 *mpls_lse, uint8_t bos)
607 {
608 *mpls_lse &= ~htonl(MPLS_BOS_MASK);
609 *mpls_lse |= htonl((bos & 0x1) << MPLS_BOS_SHIFT);
610 }
611
612 /* Set TTL in mpls lse. */
613 static inline void
614 flow_set_mpls_lse_ttl(ovs_be32 *mpls_lse, uint8_t ttl)
615 {
616 *mpls_lse &= ~htonl(MPLS_TTL_MASK);
617 *mpls_lse |= htonl(ttl << MPLS_TTL_SHIFT);
618 }
619
620 /* Given a mpls label stack entry in network byte order
621 * return mpls BoS bit */
622 static inline uint8_t
623 mpls_lse_to_bos(ovs_be32 mpls_lse)
624 {
625 return (mpls_lse & htonl(MPLS_BOS_MASK)) != 0;
626 }
627
628 #define IP_FMT "%"PRIu32".%"PRIu32".%"PRIu32".%"PRIu32
629 #define IP_ARGS(ip) \
630 ntohl(ip) >> 24, \
631 (ntohl(ip) >> 16) & 0xff, \
632 (ntohl(ip) >> 8) & 0xff, \
633 ntohl(ip) & 0xff
634
635 /* Example:
636 *
637 * char *string = "1 33.44.55.66 2";
638 * ovs_be32 ip;
639 * int a, b;
640 *
641 * if (ovs_scan(string, "%d"IP_SCAN_FMT"%d", &a, IP_SCAN_ARGS(&ip), &b)) {
642 * ...
643 * }
644 */
645 #define IP_SCAN_FMT "%"SCNu8".%"SCNu8".%"SCNu8".%"SCNu8
646 #define IP_SCAN_ARGS(ip) \
647 ((void) (ovs_be32) *(ip), &((uint8_t *) ip)[0]), \
648 &((uint8_t *) ip)[1], \
649 &((uint8_t *) ip)[2], \
650 &((uint8_t *) ip)[3]
651
652 #define IP_PORT_SCAN_FMT "%"SCNu8".%"SCNu8".%"SCNu8".%"SCNu8":%"SCNu16
653 #define IP_PORT_SCAN_ARGS(ip, port) \
654 ((void) (ovs_be32) *(ip), &((uint8_t *) ip)[0]), \
655 &((uint8_t *) ip)[1], \
656 &((uint8_t *) ip)[2], \
657 &((uint8_t *) ip)[3], \
658 ((void) (ovs_be16) *(port), (uint16_t *) port)
659
660 /* Returns true if 'netmask' is a CIDR netmask, that is, if it consists of N
661 * high-order 1-bits and 32-N low-order 0-bits. */
662 static inline bool
663 ip_is_cidr(ovs_be32 netmask)
664 {
665 uint32_t x = ~ntohl(netmask);
666 return !(x & (x + 1));
667 }
668 static inline bool
669 ip_is_multicast(ovs_be32 ip)
670 {
671 return (ip & htonl(0xf0000000)) == htonl(0xe0000000);
672 }
673 static inline bool
674 ip_is_local_multicast(ovs_be32 ip)
675 {
676 return (ip & htonl(0xffffff00)) == htonl(0xe0000000);
677 }
678 int ip_count_cidr_bits(ovs_be32 netmask);
679 void ip_format_masked(ovs_be32 ip, ovs_be32 mask, struct ds *);
680 bool ip_parse(const char *s, ovs_be32 *ip);
681 char *ip_parse_port(const char *s, ovs_be32 *ip, ovs_be16 *port)
682 OVS_WARN_UNUSED_RESULT;
683 char *ip_parse_masked(const char *s, ovs_be32 *ip, ovs_be32 *mask)
684 OVS_WARN_UNUSED_RESULT;
685 char *ip_parse_cidr(const char *s, ovs_be32 *ip, unsigned int *plen)
686 OVS_WARN_UNUSED_RESULT;
687 char *ip_parse_masked_len(const char *s, int *n, ovs_be32 *ip, ovs_be32 *mask)
688 OVS_WARN_UNUSED_RESULT;
689 char *ip_parse_cidr_len(const char *s, int *n, ovs_be32 *ip,
690 unsigned int *plen)
691 OVS_WARN_UNUSED_RESULT;
692
693 #define IP_VER(ip_ihl_ver) ((ip_ihl_ver) >> 4)
694 #define IP_IHL(ip_ihl_ver) ((ip_ihl_ver) & 15)
695 #define IP_IHL_VER(ihl, ver) (((ver) << 4) | (ihl))
696
697 #ifndef IPPROTO_SCTP
698 #define IPPROTO_SCTP 132
699 #endif
700
701 #ifndef IPPROTO_DCCP
702 #define IPPROTO_DCCP 33
703 #endif
704
705 #ifndef IPPROTO_IGMP
706 #define IPPROTO_IGMP 2
707 #endif
708
709 #ifndef IPPROTO_UDPLITE
710 #define IPPROTO_UDPLITE 136
711 #endif
712
713 /* TOS fields. */
714 #define IP_ECN_NOT_ECT 0x0
715 #define IP_ECN_ECT_1 0x01
716 #define IP_ECN_ECT_0 0x02
717 #define IP_ECN_CE 0x03
718 #define IP_ECN_MASK 0x03
719 #define IP_DSCP_CS6 0xc0
720 #define IP_DSCP_MASK 0xfc
721
722 static inline int
723 IP_ECN_is_ce(uint8_t dsfield)
724 {
725 return (dsfield & IP_ECN_MASK) == IP_ECN_CE;
726 }
727
728 #define IP_VERSION 4
729
730 #define IP_DONT_FRAGMENT 0x4000 /* Don't fragment. */
731 #define IP_MORE_FRAGMENTS 0x2000 /* More fragments. */
732 #define IP_FRAG_OFF_MASK 0x1fff /* Fragment offset. */
733 #define IP_IS_FRAGMENT(ip_frag_off) \
734 ((ip_frag_off) & htons(IP_MORE_FRAGMENTS | IP_FRAG_OFF_MASK))
735
736 #define IP_HEADER_LEN 20
737 struct ip_header {
738 uint8_t ip_ihl_ver;
739 uint8_t ip_tos;
740 ovs_be16 ip_tot_len;
741 ovs_be16 ip_id;
742 ovs_be16 ip_frag_off;
743 uint8_t ip_ttl;
744 uint8_t ip_proto;
745 ovs_be16 ip_csum;
746 ovs_16aligned_be32 ip_src;
747 ovs_16aligned_be32 ip_dst;
748 };
749 BUILD_ASSERT_DECL(IP_HEADER_LEN == sizeof(struct ip_header));
750
751 /* ICMPv4 types. */
752 #define ICMP4_ECHO_REPLY 0
753 #define ICMP4_DST_UNREACH 3
754 #define ICMP4_SOURCEQUENCH 4
755 #define ICMP4_REDIRECT 5
756 #define ICMP4_ECHO_REQUEST 8
757 #define ICMP4_TIME_EXCEEDED 11
758 #define ICMP4_PARAM_PROB 12
759 #define ICMP4_TIMESTAMP 13
760 #define ICMP4_TIMESTAMPREPLY 14
761 #define ICMP4_INFOREQUEST 15
762 #define ICMP4_INFOREPLY 16
763
764 #define ICMP_HEADER_LEN 8
765 struct icmp_header {
766 uint8_t icmp_type;
767 uint8_t icmp_code;
768 ovs_be16 icmp_csum;
769 union {
770 struct {
771 ovs_be16 id;
772 ovs_be16 seq;
773 } echo;
774 struct {
775 ovs_be16 empty;
776 ovs_be16 mtu;
777 } frag;
778 ovs_16aligned_be32 gateway;
779 } icmp_fields;
780 };
781 BUILD_ASSERT_DECL(ICMP_HEADER_LEN == sizeof(struct icmp_header));
782
783 /* ICMPV4 */
784 #define ICMP_ERROR_DATA_L4_LEN 8
785
786 #define IGMP_HEADER_LEN 8
787 struct igmp_header {
788 uint8_t igmp_type;
789 uint8_t igmp_code;
790 ovs_be16 igmp_csum;
791 ovs_16aligned_be32 group;
792 };
793 BUILD_ASSERT_DECL(IGMP_HEADER_LEN == sizeof(struct igmp_header));
794
795 #define IGMPV3_HEADER_LEN 8
796 struct igmpv3_header {
797 uint8_t type;
798 uint8_t rsvr1;
799 ovs_be16 csum;
800 ovs_be16 rsvr2;
801 ovs_be16 ngrp;
802 };
803 BUILD_ASSERT_DECL(IGMPV3_HEADER_LEN == sizeof(struct igmpv3_header));
804
805 #define IGMPV3_QUERY_HEADER_LEN 12
806 struct igmpv3_query_header {
807 uint8_t type;
808 uint8_t max_resp;
809 ovs_be16 csum;
810 ovs_16aligned_be32 group;
811 uint8_t srs_qrv;
812 uint8_t qqic;
813 ovs_be16 nsrcs;
814 };
815 BUILD_ASSERT_DECL(
816 IGMPV3_QUERY_HEADER_LEN == sizeof(struct igmpv3_query_header
817 ));
818
819 #define IGMPV3_RECORD_LEN 8
820 struct igmpv3_record {
821 uint8_t type;
822 uint8_t aux_len;
823 ovs_be16 nsrcs;
824 ovs_16aligned_be32 maddr;
825 };
826 BUILD_ASSERT_DECL(IGMPV3_RECORD_LEN == sizeof(struct igmpv3_record));
827
828 #define IGMP_HOST_MEMBERSHIP_QUERY 0x11 /* From RFC1112 */
829 #define IGMP_HOST_MEMBERSHIP_REPORT 0x12 /* Ditto */
830 #define IGMPV2_HOST_MEMBERSHIP_REPORT 0x16 /* V2 version of 0x12 */
831 #define IGMP_HOST_LEAVE_MESSAGE 0x17
832 #define IGMPV3_HOST_MEMBERSHIP_REPORT 0x22 /* V3 version of 0x12 */
833
834 /*
835 * IGMPv3 and MLDv2 use the same codes.
836 */
837 #define IGMPV3_MODE_IS_INCLUDE 1
838 #define IGMPV3_MODE_IS_EXCLUDE 2
839 #define IGMPV3_CHANGE_TO_INCLUDE_MODE 3
840 #define IGMPV3_CHANGE_TO_EXCLUDE_MODE 4
841 #define IGMPV3_ALLOW_NEW_SOURCES 5
842 #define IGMPV3_BLOCK_OLD_SOURCES 6
843
844 #define SCTP_HEADER_LEN 12
845 struct sctp_header {
846 ovs_be16 sctp_src;
847 ovs_be16 sctp_dst;
848 ovs_16aligned_be32 sctp_vtag;
849 ovs_16aligned_be32 sctp_csum;
850 };
851 BUILD_ASSERT_DECL(SCTP_HEADER_LEN == sizeof(struct sctp_header));
852
853 #define UDP_HEADER_LEN 8
854 struct udp_header {
855 ovs_be16 udp_src;
856 ovs_be16 udp_dst;
857 ovs_be16 udp_len;
858 ovs_be16 udp_csum;
859 };
860 BUILD_ASSERT_DECL(UDP_HEADER_LEN == sizeof(struct udp_header));
861
862 #define ESP_HEADER_LEN 8
863 struct esp_header {
864 ovs_be32 spi;
865 ovs_be32 seq_no;
866 };
867 BUILD_ASSERT_DECL(ESP_HEADER_LEN == sizeof(struct esp_header));
868
869 #define ESP_TRAILER_LEN 2
870 struct esp_trailer {
871 uint8_t pad_len;
872 uint8_t next_hdr;
873 };
874 BUILD_ASSERT_DECL(ESP_TRAILER_LEN == sizeof(struct esp_trailer));
875
876 #define TCP_FIN 0x001
877 #define TCP_SYN 0x002
878 #define TCP_RST 0x004
879 #define TCP_PSH 0x008
880 #define TCP_ACK 0x010
881 #define TCP_URG 0x020
882 #define TCP_ECE 0x040
883 #define TCP_CWR 0x080
884 #define TCP_NS 0x100
885
886 #define TCP_CTL(flags, offset) (htons((flags) | ((offset) << 12)))
887 #define TCP_FLAGS(tcp_ctl) (ntohs(tcp_ctl) & 0x0fff)
888 #define TCP_FLAGS_BE16(tcp_ctl) ((tcp_ctl) & htons(0x0fff))
889 #define TCP_OFFSET(tcp_ctl) (ntohs(tcp_ctl) >> 12)
890
891 #define TCP_HEADER_LEN 20
892 struct tcp_header {
893 ovs_be16 tcp_src;
894 ovs_be16 tcp_dst;
895 ovs_16aligned_be32 tcp_seq;
896 ovs_16aligned_be32 tcp_ack;
897 ovs_be16 tcp_ctl;
898 ovs_be16 tcp_winsz;
899 ovs_be16 tcp_csum;
900 ovs_be16 tcp_urg;
901 };
902 BUILD_ASSERT_DECL(TCP_HEADER_LEN == sizeof(struct tcp_header));
903
904 /* Connection states.
905 *
906 * Names like CS_RELATED are bit values, e.g. 1 << 2.
907 * Names like CS_RELATED_BIT are bit indexes, e.g. 2. */
908 #define CS_STATES \
909 CS_STATE(NEW, 0, "new") \
910 CS_STATE(ESTABLISHED, 1, "est") \
911 CS_STATE(RELATED, 2, "rel") \
912 CS_STATE(REPLY_DIR, 3, "rpl") \
913 CS_STATE(INVALID, 4, "inv") \
914 CS_STATE(TRACKED, 5, "trk") \
915 CS_STATE(SRC_NAT, 6, "snat") \
916 CS_STATE(DST_NAT, 7, "dnat")
917
918 enum {
919 #define CS_STATE(ENUM, INDEX, NAME) \
920 CS_##ENUM = 1 << INDEX, \
921 CS_##ENUM##_BIT = INDEX,
922 CS_STATES
923 #undef CS_STATE
924 };
925
926 /* Undefined connection state bits. */
927 enum {
928 #define CS_STATE(ENUM, INDEX, NAME) +CS_##ENUM
929 CS_SUPPORTED_MASK = CS_STATES
930 #undef CS_STATE
931 };
932 #define CS_UNSUPPORTED_MASK (~(uint32_t)CS_SUPPORTED_MASK)
933
934 #define ARP_HRD_ETHERNET 1
935 #define ARP_PRO_IP 0x0800
936 #define ARP_OP_REQUEST 1
937 #define ARP_OP_REPLY 2
938 #define ARP_OP_RARP 3
939
940 #define ARP_ETH_HEADER_LEN 28
941 struct arp_eth_header {
942 /* Generic members. */
943 ovs_be16 ar_hrd; /* Hardware type. */
944 ovs_be16 ar_pro; /* Protocol type. */
945 uint8_t ar_hln; /* Hardware address length. */
946 uint8_t ar_pln; /* Protocol address length. */
947 ovs_be16 ar_op; /* Opcode. */
948
949 /* Ethernet+IPv4 specific members. */
950 struct eth_addr ar_sha; /* Sender hardware address. */
951 ovs_16aligned_be32 ar_spa; /* Sender protocol address. */
952 struct eth_addr ar_tha; /* Target hardware address. */
953 ovs_16aligned_be32 ar_tpa; /* Target protocol address. */
954 };
955 BUILD_ASSERT_DECL(ARP_ETH_HEADER_LEN == sizeof(struct arp_eth_header));
956
957 #define IPV6_HEADER_LEN 40
958
959 /* Like struct in6_addr, but whereas that struct requires 32-bit alignment on
960 * most implementations, this one only requires 16-bit alignment. */
961 union ovs_16aligned_in6_addr {
962 ovs_be16 be16[8];
963 ovs_16aligned_be32 be32[4];
964 };
965
966 /* Like struct in6_hdr, but whereas that struct requires 32-bit alignment, this
967 * one only requires 16-bit alignment. */
968 struct ovs_16aligned_ip6_hdr {
969 union {
970 struct ovs_16aligned_ip6_hdrctl {
971 ovs_16aligned_be32 ip6_un1_flow;
972 ovs_be16 ip6_un1_plen;
973 uint8_t ip6_un1_nxt;
974 uint8_t ip6_un1_hlim;
975 } ip6_un1;
976 uint8_t ip6_un2_vfc;
977 } ip6_ctlun;
978 union ovs_16aligned_in6_addr ip6_src;
979 union ovs_16aligned_in6_addr ip6_dst;
980 };
981
982 /* Like struct in6_frag, but whereas that struct requires 32-bit alignment,
983 * this one only requires 16-bit alignment. */
984 struct ovs_16aligned_ip6_frag {
985 uint8_t ip6f_nxt;
986 uint8_t ip6f_reserved;
987 ovs_be16 ip6f_offlg;
988 ovs_16aligned_be32 ip6f_ident;
989 };
990
991 #define ICMP6_HEADER_LEN 4
992 struct icmp6_header {
993 uint8_t icmp6_type;
994 uint8_t icmp6_code;
995 ovs_be16 icmp6_cksum;
996 };
997 BUILD_ASSERT_DECL(ICMP6_HEADER_LEN == sizeof(struct icmp6_header));
998
999 #define ICMP6_DATA_HEADER_LEN 8
1000 struct icmp6_data_header {
1001 struct icmp6_header icmp6_base;
1002 union {
1003 ovs_16aligned_be32 be32[1];
1004 ovs_be16 be16[2];
1005 uint8_t u8[4];
1006 } icmp6_data;
1007 };
1008 BUILD_ASSERT_DECL(ICMP6_DATA_HEADER_LEN == sizeof(struct icmp6_data_header));
1009
1010 uint32_t packet_csum_pseudoheader6(const struct ovs_16aligned_ip6_hdr *);
1011 ovs_be16 packet_csum_upperlayer6(const struct ovs_16aligned_ip6_hdr *,
1012 const void *, uint8_t, uint16_t);
1013
1014 /* Neighbor Discovery option field.
1015 * ND options are always a multiple of 8 bytes in size. */
1016 #define ND_LLA_OPT_LEN 8
1017 struct ovs_nd_lla_opt {
1018 uint8_t type; /* One of ND_OPT_*_LINKADDR. */
1019 uint8_t len;
1020 struct eth_addr mac;
1021 };
1022 BUILD_ASSERT_DECL(ND_LLA_OPT_LEN == sizeof(struct ovs_nd_lla_opt));
1023
1024 /* Neighbor Discovery option: Prefix Information. */
1025 #define ND_PREFIX_OPT_LEN 32
1026 struct ovs_nd_prefix_opt {
1027 uint8_t type; /* ND_OPT_PREFIX_INFORMATION. */
1028 uint8_t len; /* Always 4. */
1029 uint8_t prefix_len;
1030 uint8_t la_flags; /* ND_PREFIX_* flags. */
1031 ovs_16aligned_be32 valid_lifetime;
1032 ovs_16aligned_be32 preferred_lifetime;
1033 ovs_16aligned_be32 reserved; /* Always 0. */
1034 union ovs_16aligned_in6_addr prefix;
1035 };
1036 BUILD_ASSERT_DECL(ND_PREFIX_OPT_LEN == sizeof(struct ovs_nd_prefix_opt));
1037
1038 /* Neighbor Discovery option: MTU. */
1039 #define ND_MTU_OPT_LEN 8
1040 #define ND_MTU_DEFAULT 0
1041 struct ovs_nd_mtu_opt {
1042 uint8_t type; /* ND_OPT_MTU */
1043 uint8_t len; /* Always 1. */
1044 ovs_be16 reserved; /* Always 0. */
1045 ovs_16aligned_be32 mtu;
1046 };
1047 BUILD_ASSERT_DECL(ND_MTU_OPT_LEN == sizeof(struct ovs_nd_mtu_opt));
1048
1049 /* Like struct nd_msg (from ndisc.h), but whereas that struct requires 32-bit
1050 * alignment, this one only requires 16-bit alignment. */
1051 #define ND_MSG_LEN 24
1052 struct ovs_nd_msg {
1053 struct icmp6_header icmph;
1054 ovs_16aligned_be32 rso_flags;
1055 union ovs_16aligned_in6_addr target;
1056 struct ovs_nd_lla_opt options[0];
1057 };
1058 BUILD_ASSERT_DECL(ND_MSG_LEN == sizeof(struct ovs_nd_msg));
1059
1060 /* Neighbor Discovery packet flags. */
1061 #define ND_RSO_ROUTER 0x80000000
1062 #define ND_RSO_SOLICITED 0x40000000
1063 #define ND_RSO_OVERRIDE 0x20000000
1064
1065 #define RA_MSG_LEN 16
1066 struct ovs_ra_msg {
1067 struct icmp6_header icmph;
1068 uint8_t cur_hop_limit;
1069 uint8_t mo_flags; /* ND_RA_MANAGED_ADDRESS and ND_RA_OTHER_CONFIG flags. */
1070 ovs_be16 router_lifetime;
1071 ovs_be32 reachable_time;
1072 ovs_be32 retrans_timer;
1073 struct ovs_nd_lla_opt options[0];
1074 };
1075 BUILD_ASSERT_DECL(RA_MSG_LEN == sizeof(struct ovs_ra_msg));
1076
1077 #define ND_RA_MANAGED_ADDRESS 0x80
1078 #define ND_RA_OTHER_CONFIG 0x40
1079
1080 /* Defaults based on MaxRtrInterval and MinRtrInterval from RFC 4861 section
1081 * 6.2.1
1082 */
1083 #define ND_RA_MAX_INTERVAL_DEFAULT 600
1084
1085 static inline int
1086 nd_ra_min_interval_default(int max)
1087 {
1088 return max >= 9 ? max / 3 : max * 3 / 4;
1089 }
1090
1091 /*
1092 * Use the same struct for MLD and MLD2, naming members as the defined fields in
1093 * in the corresponding version of the protocol, though they are reserved in the
1094 * other one.
1095 */
1096 #define MLD_HEADER_LEN 8
1097 struct mld_header {
1098 uint8_t type;
1099 uint8_t code;
1100 ovs_be16 csum;
1101 ovs_be16 mrd;
1102 ovs_be16 ngrp;
1103 };
1104 BUILD_ASSERT_DECL(MLD_HEADER_LEN == sizeof(struct mld_header));
1105
1106 #define MLD2_RECORD_LEN 20
1107 struct mld2_record {
1108 uint8_t type;
1109 uint8_t aux_len;
1110 ovs_be16 nsrcs;
1111 union ovs_16aligned_in6_addr maddr;
1112 };
1113 BUILD_ASSERT_DECL(MLD2_RECORD_LEN == sizeof(struct mld2_record));
1114
1115 #define MLD_QUERY 130
1116 #define MLD_REPORT 131
1117 #define MLD_DONE 132
1118 #define MLD2_REPORT 143
1119
1120 /* The IPv6 flow label is in the lower 20 bits of the first 32-bit word. */
1121 #define IPV6_LABEL_MASK 0x000fffff
1122
1123 /* Example:
1124 *
1125 * char *string = "1 ::1 2";
1126 * char ipv6_s[IPV6_SCAN_LEN + 1];
1127 * struct in6_addr ipv6;
1128 *
1129 * if (ovs_scan(string, "%d"IPV6_SCAN_FMT"%d", &a, ipv6_s, &b)
1130 * && inet_pton(AF_INET6, ipv6_s, &ipv6) == 1) {
1131 * ...
1132 * }
1133 */
1134 #define IPV6_SCAN_FMT "%46[0123456789abcdefABCDEF:.]"
1135 #define IPV6_SCAN_LEN 46
1136
1137 extern const struct in6_addr in6addr_exact;
1138 #define IN6ADDR_EXACT_INIT { { { 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, \
1139 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff } } }
1140
1141 extern const struct in6_addr in6addr_all_hosts;
1142 #define IN6ADDR_ALL_HOSTS_INIT { { { 0xff,0x02,0x00,0x00,0x00,0x00,0x00,0x00, \
1143 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01 } } }
1144
1145 extern const struct in6_addr in6addr_all_routers;
1146 #define IN6ADDR_ALL_ROUTERS_INIT { { { 0xff,0x02,0x00,0x00,0x00,0x00,0x00,0x00, \
1147 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02 } } }
1148
1149 static inline bool ipv6_addr_equals(const struct in6_addr *a,
1150 const struct in6_addr *b)
1151 {
1152 #ifdef IN6_ARE_ADDR_EQUAL
1153 return IN6_ARE_ADDR_EQUAL(a, b);
1154 #else
1155 return !memcmp(a, b, sizeof(*a));
1156 #endif
1157 }
1158
1159 /* Checks the IPv6 address in 'mask' for all zeroes. */
1160 static inline bool ipv6_mask_is_any(const struct in6_addr *mask) {
1161 return ipv6_addr_equals(mask, &in6addr_any);
1162 }
1163
1164 static inline bool ipv6_mask_is_exact(const struct in6_addr *mask) {
1165 return ipv6_addr_equals(mask, &in6addr_exact);
1166 }
1167
1168 static inline bool ipv6_is_all_hosts(const struct in6_addr *addr) {
1169 return ipv6_addr_equals(addr, &in6addr_all_hosts);
1170 }
1171
1172 static inline bool ipv6_addr_is_set(const struct in6_addr *addr) {
1173 return !ipv6_addr_equals(addr, &in6addr_any);
1174 }
1175
1176 static inline bool ipv6_addr_is_multicast(const struct in6_addr *ip) {
1177 return ip->s6_addr[0] == 0xff;
1178 }
1179
1180 static inline struct in6_addr
1181 in6_addr_mapped_ipv4(ovs_be32 ip4)
1182 {
1183 struct in6_addr ip6;
1184 memset(&ip6, 0, sizeof(ip6));
1185 ip6.s6_addr[10] = 0xff, ip6.s6_addr[11] = 0xff;
1186 memcpy(&ip6.s6_addr[12], &ip4, 4);
1187 return ip6;
1188 }
1189
1190 static inline void
1191 in6_addr_set_mapped_ipv4(struct in6_addr *ip6, ovs_be32 ip4)
1192 {
1193 *ip6 = in6_addr_mapped_ipv4(ip4);
1194 }
1195
1196 static inline ovs_be32
1197 in6_addr_get_mapped_ipv4(const struct in6_addr *addr)
1198 {
1199 union ovs_16aligned_in6_addr *taddr =
1200 (union ovs_16aligned_in6_addr *) addr;
1201 if (IN6_IS_ADDR_V4MAPPED(addr)) {
1202 return get_16aligned_be32(&taddr->be32[3]);
1203 } else {
1204 return INADDR_ANY;
1205 }
1206 }
1207
1208 static inline void
1209 in6_addr_solicited_node(struct in6_addr *addr, const struct in6_addr *ip6)
1210 {
1211 union ovs_16aligned_in6_addr *taddr =
1212 (union ovs_16aligned_in6_addr *) addr;
1213 memset(taddr->be16, 0, sizeof(taddr->be16));
1214 taddr->be16[0] = htons(0xff02);
1215 taddr->be16[5] = htons(0x1);
1216 taddr->be16[6] = htons(0xff00);
1217 memcpy(&addr->s6_addr[13], &ip6->s6_addr[13], 3);
1218 }
1219
1220 /*
1221 * Generates ipv6 EUI64 address from the given eth addr
1222 * and prefix and stores it in 'lla'
1223 */
1224 static inline void
1225 in6_generate_eui64(struct eth_addr ea, struct in6_addr *prefix,
1226 struct in6_addr *lla)
1227 {
1228 union ovs_16aligned_in6_addr *taddr =
1229 (union ovs_16aligned_in6_addr *) lla;
1230 union ovs_16aligned_in6_addr *prefix_taddr =
1231 (union ovs_16aligned_in6_addr *) prefix;
1232 taddr->be16[0] = prefix_taddr->be16[0];
1233 taddr->be16[1] = prefix_taddr->be16[1];
1234 taddr->be16[2] = prefix_taddr->be16[2];
1235 taddr->be16[3] = prefix_taddr->be16[3];
1236 taddr->be16[4] = htons(((ea.ea[0] ^ 0x02) << 8) | ea.ea[1]);
1237 taddr->be16[5] = htons(ea.ea[2] << 8 | 0x00ff);
1238 taddr->be16[6] = htons(0xfe << 8 | ea.ea[3]);
1239 taddr->be16[7] = ea.be16[2];
1240 }
1241
1242 /*
1243 * Generates ipv6 link local address from the given eth addr
1244 * with prefix 'fe80::/64' and stores it in 'lla'
1245 */
1246 static inline void
1247 in6_generate_lla(struct eth_addr ea, struct in6_addr *lla)
1248 {
1249 union ovs_16aligned_in6_addr *taddr =
1250 (union ovs_16aligned_in6_addr *) lla;
1251 memset(taddr->be16, 0, sizeof(taddr->be16));
1252 taddr->be16[0] = htons(0xfe80);
1253 taddr->be16[4] = htons(((ea.ea[0] ^ 0x02) << 8) | ea.ea[1]);
1254 taddr->be16[5] = htons(ea.ea[2] << 8 | 0x00ff);
1255 taddr->be16[6] = htons(0xfe << 8 | ea.ea[3]);
1256 taddr->be16[7] = ea.be16[2];
1257 }
1258
1259 /* Returns true if 'addr' is a link local address. Otherwise, false. */
1260 static inline bool
1261 in6_is_lla(struct in6_addr *addr)
1262 {
1263 #ifdef s6_addr32
1264 return addr->s6_addr32[0] == htonl(0xfe800000) && !(addr->s6_addr32[1]);
1265 #else
1266 return addr->s6_addr[0] == 0xfe && addr->s6_addr[1] == 0x80 &&
1267 !(addr->s6_addr[2] | addr->s6_addr[3] | addr->s6_addr[4] |
1268 addr->s6_addr[5] | addr->s6_addr[6] | addr->s6_addr[7]);
1269 #endif
1270 }
1271
1272 static inline void
1273 ipv6_multicast_to_ethernet(struct eth_addr *eth, const struct in6_addr *ip6)
1274 {
1275 eth->ea[0] = 0x33;
1276 eth->ea[1] = 0x33;
1277 eth->ea[2] = ip6->s6_addr[12];
1278 eth->ea[3] = ip6->s6_addr[13];
1279 eth->ea[4] = ip6->s6_addr[14];
1280 eth->ea[5] = ip6->s6_addr[15];
1281 }
1282
1283 static inline bool dl_type_is_ip_any(ovs_be16 dl_type)
1284 {
1285 return dl_type == htons(ETH_TYPE_IP)
1286 || dl_type == htons(ETH_TYPE_IPV6);
1287 }
1288
1289 /* Tunnel header */
1290
1291 /* GRE protocol header */
1292 struct gre_base_hdr {
1293 ovs_be16 flags;
1294 ovs_be16 protocol;
1295 };
1296
1297 #define GRE_CSUM 0x8000
1298 #define GRE_ROUTING 0x4000
1299 #define GRE_KEY 0x2000
1300 #define GRE_SEQ 0x1000
1301 #define GRE_STRICT 0x0800
1302 #define GRE_REC 0x0700
1303 #define GRE_FLAGS 0x00F8
1304 #define GRE_VERSION 0x0007
1305
1306 /*
1307 * ERSPAN protocol header and metadata
1308 *
1309 * Version 1 (Type II) header (8 octets [42:49])
1310 * 0 1 2 3
1311 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
1312 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1313 * | Ver | VLAN | COS | En|T| Session ID |
1314 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1315 * | Reserved | Index |
1316 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1317 *
1318 *
1319 * ERSPAN Version 2 (Type III) header (12 octets [42:49])
1320 * 0 1 2 3
1321 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
1322 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1323 * | Ver | VLAN | COS |BSO|T| Session ID |
1324 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1325 * | Timestamp |
1326 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1327 * | SGT |P| FT | Hw ID |D|Gra|O|
1328 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1329 *
1330 */
1331
1332 /* ERSPAN has fixed 8-byte GRE header */
1333 #define ERSPAN_GREHDR_LEN 8
1334 #define ERSPAN_HDR(gre_base_hdr) \
1335 ((struct erspan_base_hdr *)((char *)gre_base_hdr + ERSPAN_GREHDR_LEN))
1336
1337 #define ERSPAN_V1_MDSIZE 4
1338 #define ERSPAN_V2_MDSIZE 8
1339
1340 #define ERSPAN_SID_MASK 0x03ff /* 10-bit Session ID. */
1341 #define ERSPAN_IDX_MASK 0xfffff /* v1 Index */
1342 #define ERSPAN_HWID_MASK 0x03f0
1343 #define ERSPAN_DIR_MASK 0x0008
1344
1345 struct erspan_base_hdr {
1346 #ifdef WORDS_BIGENDIAN
1347 uint8_t ver:4,
1348 vlan_upper:4;
1349 uint8_t vlan:8;
1350 uint8_t cos:3,
1351 en:2,
1352 t:1,
1353 session_id_upper:2;
1354 uint8_t session_id:8;
1355 #else
1356 uint8_t vlan_upper:4,
1357 ver:4;
1358 uint8_t vlan:8;
1359 uint8_t session_id_upper:2,
1360 t:1,
1361 en:2,
1362 cos:3;
1363 uint8_t session_id:8;
1364 #endif
1365 };
1366
1367 struct erspan_md2 {
1368 ovs_16aligned_be32 timestamp;
1369 ovs_be16 sgt;
1370 #ifdef WORDS_BIGENDIAN
1371 uint8_t p:1,
1372 ft:5,
1373 hwid_upper:2;
1374 uint8_t hwid:4,
1375 dir:1,
1376 gra:2,
1377 o:1;
1378 #else
1379 uint8_t hwid_upper:2,
1380 ft:5,
1381 p:1;
1382 uint8_t o:1,
1383 gra:2,
1384 dir:1,
1385 hwid:4;
1386 #endif
1387 };
1388
1389 struct erspan_metadata {
1390 int version;
1391 union {
1392 ovs_be32 index; /* Version 1 (type II)*/
1393 struct erspan_md2 md2; /* Version 2 (type III) */
1394 } u;
1395 };
1396
1397 static inline uint16_t get_sid(const struct erspan_base_hdr *ershdr)
1398 {
1399 return (ershdr->session_id_upper << 8) + ershdr->session_id;
1400 }
1401
1402 static inline void set_sid(struct erspan_base_hdr *ershdr, uint16_t id)
1403 {
1404 ershdr->session_id = id & 0xff;
1405 ershdr->session_id_upper = (id >> 8) &0x3;
1406 }
1407
1408 static inline uint8_t get_hwid(const struct erspan_md2 *md2)
1409 {
1410 return (md2->hwid_upper << 4) + md2->hwid;
1411 }
1412
1413 static inline void set_hwid(struct erspan_md2 *md2, uint8_t hwid)
1414 {
1415 md2->hwid = hwid & 0xf;
1416 md2->hwid_upper = (hwid >> 4) & 0x3;
1417 }
1418
1419 /* ERSPAN timestamp granularity
1420 * 00b --> granularity = 100 microseconds
1421 * 01b --> granularity = 100 nanoseconds
1422 * 10b --> granularity = IEEE 1588
1423 * Here we only support 100 microseconds.
1424 */
1425 enum erspan_ts_gra {
1426 ERSPAN_100US,
1427 ERSPAN_100NS,
1428 ERSPAN_IEEE1588,
1429 };
1430
1431 static inline ovs_be32 get_erspan_ts(enum erspan_ts_gra gra)
1432 {
1433 ovs_be32 ts = 0;
1434
1435 switch (gra) {
1436 case ERSPAN_100US:
1437 ts = htonl((uint32_t)(time_wall_usec() / 100));
1438 break;
1439 case ERSPAN_100NS:
1440 /* fall back */
1441 case ERSPAN_IEEE1588:
1442 /* fall back */
1443 default:
1444 OVS_NOT_REACHED();
1445 break;
1446 }
1447 return ts;
1448 }
1449
1450 /* VXLAN protocol header */
1451 struct vxlanhdr {
1452 union {
1453 ovs_16aligned_be32 vx_flags; /* VXLAN flags. */
1454 struct {
1455 uint8_t flags; /* VXLAN GPE flags. */
1456 uint8_t reserved[2]; /* 16 bits reserved. */
1457 uint8_t next_protocol; /* Next Protocol field for VXLAN GPE. */
1458 } vx_gpe;
1459 };
1460 ovs_16aligned_be32 vx_vni;
1461 };
1462 BUILD_ASSERT_DECL(sizeof(struct vxlanhdr) == 8);
1463
1464 #define VXLAN_FLAGS 0x08000000 /* struct vxlanhdr.vx_flags required value. */
1465
1466 /*
1467 * VXLAN Generic Protocol Extension (VXLAN_F_GPE):
1468 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1469 * |R|R|Ver|I|P|R|O| Reserved |Next Protocol |
1470 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1471 * | VXLAN Network Identifier (VNI) | Reserved |
1472 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
1473 *
1474 * Ver = Version. Indicates VXLAN GPE protocol version.
1475 *
1476 * P = Next Protocol Bit. The P bit is set to indicate that the
1477 * Next Protocol field is present.
1478 *
1479 * O = OAM Flag Bit. The O bit is set to indicate that the packet
1480 * is an OAM packet.
1481 *
1482 * Next Protocol = This 8 bit field indicates the protocol header
1483 * immediately following the VXLAN GPE header.
1484 *
1485 * https://tools.ietf.org/html/draft-ietf-nvo3-vxlan-gpe-01
1486 */
1487
1488 /* Fields in struct vxlanhdr.vx_gpe.flags */
1489 #define VXLAN_GPE_FLAGS_VER 0x30 /* Version. */
1490 #define VLXAN_GPE_FLAGS_P 0x04 /* Next Protocol Bit. */
1491 #define VXLAN_GPE_FLAGS_O 0x01 /* OAM Bit. */
1492
1493 /* VXLAN-GPE header flags. */
1494 #define VXLAN_HF_VER ((1U <<29) | (1U <<28))
1495 #define VXLAN_HF_NP (1U <<26)
1496 #define VXLAN_HF_OAM (1U <<24)
1497
1498 #define VXLAN_GPE_USED_BITS (VXLAN_HF_VER | VXLAN_HF_NP | VXLAN_HF_OAM | \
1499 0xff)
1500
1501 /* VXLAN-GPE header Next Protocol. */
1502 #define VXLAN_GPE_NP_IPV4 0x01
1503 #define VXLAN_GPE_NP_IPV6 0x02
1504 #define VXLAN_GPE_NP_ETHERNET 0x03
1505 #define VXLAN_GPE_NP_NSH 0x04
1506
1507 #define VXLAN_F_GPE 0x4000
1508 #define VXLAN_HF_GPE 0x04000000
1509
1510 /* Input values for PACKET_TYPE macros have to be in host byte order.
1511 * The _BE postfix indicates result is in network byte order. Otherwise result
1512 * is in host byte order. */
1513 #define PACKET_TYPE(NS, NS_TYPE) ((uint32_t) ((NS) << 16 | (NS_TYPE)))
1514 #define PACKET_TYPE_BE(NS, NS_TYPE) (htonl((NS) << 16 | (NS_TYPE)))
1515
1516 /* Returns the host byte ordered namespace of 'packet type'. */
1517 static inline uint16_t
1518 pt_ns(ovs_be32 packet_type)
1519 {
1520 return ntohl(packet_type) >> 16;
1521 }
1522
1523 /* Returns the network byte ordered namespace type of 'packet type'. */
1524 static inline ovs_be16
1525 pt_ns_type_be(ovs_be32 packet_type)
1526 {
1527 return be32_to_be16(packet_type);
1528 }
1529
1530 /* Returns the host byte ordered namespace type of 'packet type'. */
1531 static inline uint16_t
1532 pt_ns_type(ovs_be32 packet_type)
1533 {
1534 return ntohs(pt_ns_type_be(packet_type));
1535 }
1536
1537 /* Well-known packet_type field values. */
1538 enum packet_type {
1539 PT_ETH = PACKET_TYPE(OFPHTN_ONF, 0x0000), /* Default PT: Ethernet */
1540 PT_USE_NEXT_PROTO = PACKET_TYPE(OFPHTN_ONF, 0xfffe), /* Pseudo PT for decap. */
1541 PT_IPV4 = PACKET_TYPE(OFPHTN_ETHERTYPE, ETH_TYPE_IP),
1542 PT_IPV6 = PACKET_TYPE(OFPHTN_ETHERTYPE, ETH_TYPE_IPV6),
1543 PT_MPLS = PACKET_TYPE(OFPHTN_ETHERTYPE, ETH_TYPE_MPLS),
1544 PT_MPLS_MC = PACKET_TYPE(OFPHTN_ETHERTYPE, ETH_TYPE_MPLS_MCAST),
1545 PT_NSH = PACKET_TYPE(OFPHTN_ETHERTYPE, ETH_TYPE_NSH),
1546 PT_UNKNOWN = PACKET_TYPE(0xffff, 0xffff), /* Unknown packet type. */
1547 };
1548
1549
1550 void ipv6_format_addr(const struct in6_addr *addr, struct ds *);
1551 void ipv6_format_addr_bracket(const struct in6_addr *addr, struct ds *,
1552 bool bracket);
1553 void ipv6_format_mapped(const struct in6_addr *addr, struct ds *);
1554 void ipv6_format_masked(const struct in6_addr *addr,
1555 const struct in6_addr *mask, struct ds *);
1556 const char * ipv6_string_mapped(char *addr_str, const struct in6_addr *addr);
1557 struct in6_addr ipv6_addr_bitand(const struct in6_addr *src,
1558 const struct in6_addr *mask);
1559 struct in6_addr ipv6_addr_bitxor(const struct in6_addr *a,
1560 const struct in6_addr *b);
1561 bool ipv6_is_zero(const struct in6_addr *a);
1562 struct in6_addr ipv6_create_mask(int mask);
1563 int ipv6_count_cidr_bits(const struct in6_addr *netmask);
1564 bool ipv6_is_cidr(const struct in6_addr *netmask);
1565
1566 bool ipv6_parse(const char *s, struct in6_addr *ip);
1567 char *ipv6_parse_masked(const char *s, struct in6_addr *ipv6,
1568 struct in6_addr *mask);
1569 char *ipv6_parse_cidr(const char *s, struct in6_addr *ip, unsigned int *plen)
1570 OVS_WARN_UNUSED_RESULT;
1571 char *ipv6_parse_masked_len(const char *s, int *n, struct in6_addr *ipv6,
1572 struct in6_addr *mask);
1573 char *ipv6_parse_cidr_len(const char *s, int *n, struct in6_addr *ip,
1574 unsigned int *plen)
1575 OVS_WARN_UNUSED_RESULT;
1576
1577 void *eth_compose(struct dp_packet *, const struct eth_addr eth_dst,
1578 const struct eth_addr eth_src, uint16_t eth_type,
1579 size_t size);
1580 void *snap_compose(struct dp_packet *, const struct eth_addr eth_dst,
1581 const struct eth_addr eth_src,
1582 unsigned int oui, uint16_t snap_type, size_t size);
1583 void packet_set_ipv4(struct dp_packet *, ovs_be32 src, ovs_be32 dst, uint8_t tos,
1584 uint8_t ttl);
1585 void packet_set_ipv4_addr(struct dp_packet *packet, ovs_16aligned_be32 *addr,
1586 ovs_be32 new_addr);
1587 void packet_set_ipv6(struct dp_packet *, const struct in6_addr *src,
1588 const struct in6_addr *dst, uint8_t tc,
1589 ovs_be32 fl, uint8_t hlmit);
1590 void packet_set_ipv6_addr(struct dp_packet *packet, uint8_t proto,
1591 ovs_16aligned_be32 addr[4],
1592 const struct in6_addr *new_addr,
1593 bool recalculate_csum);
1594 void packet_set_tcp_port(struct dp_packet *, ovs_be16 src, ovs_be16 dst);
1595 void packet_set_udp_port(struct dp_packet *, ovs_be16 src, ovs_be16 dst);
1596 void packet_set_sctp_port(struct dp_packet *, ovs_be16 src, ovs_be16 dst);
1597 void packet_set_icmp(struct dp_packet *, uint8_t type, uint8_t code);
1598 void packet_set_nd(struct dp_packet *, const struct in6_addr *target,
1599 const struct eth_addr sll, const struct eth_addr tll);
1600 void packet_set_nd_ext(struct dp_packet *packet,
1601 const ovs_16aligned_be32 rso_flags,
1602 const uint8_t opt_type);
1603 void packet_set_igmp3_query(struct dp_packet *, uint8_t max_resp,
1604 ovs_be32 group, bool srs, uint8_t qrv,
1605 uint8_t qqic);
1606 void packet_format_tcp_flags(struct ds *, uint16_t);
1607 const char *packet_tcp_flag_to_string(uint32_t flag);
1608 void compose_arp__(struct dp_packet *);
1609 void compose_arp(struct dp_packet *, uint16_t arp_op,
1610 const struct eth_addr arp_sha,
1611 const struct eth_addr arp_tha, bool broadcast,
1612 ovs_be32 arp_spa, ovs_be32 arp_tpa);
1613 void compose_nd_ns(struct dp_packet *, const struct eth_addr eth_src,
1614 const struct in6_addr *ipv6_src,
1615 const struct in6_addr *ipv6_dst);
1616 void compose_nd_na(struct dp_packet *, const struct eth_addr eth_src,
1617 const struct eth_addr eth_dst,
1618 const struct in6_addr *ipv6_src,
1619 const struct in6_addr *ipv6_dst,
1620 ovs_be32 rso_flags);
1621 void compose_nd_ra(struct dp_packet *,
1622 const struct eth_addr eth_src,
1623 const struct eth_addr eth_dst,
1624 const struct in6_addr *ipv6_src,
1625 const struct in6_addr *ipv6_dst,
1626 uint8_t cur_hop_limit, uint8_t mo_flags,
1627 ovs_be16 router_lt, ovs_be32 reachable_time,
1628 ovs_be32 retrans_timer, uint32_t mtu);
1629 void packet_put_ra_prefix_opt(struct dp_packet *,
1630 uint8_t plen, uint8_t la_flags,
1631 ovs_be32 valid_lifetime,
1632 ovs_be32 preferred_lifetime,
1633 const ovs_be128 router_prefix);
1634 uint32_t packet_csum_pseudoheader(const struct ip_header *);
1635 void IP_ECN_set_ce(struct dp_packet *pkt, bool is_ipv6);
1636
1637 #define DNS_HEADER_LEN 12
1638 struct dns_header {
1639 ovs_be16 id;
1640 uint8_t lo_flag; /* QR (1), OPCODE (4), AA (1), TC (1) and RD (1) */
1641 uint8_t hi_flag; /* RA (1), Z (3) and RCODE (4) */
1642 ovs_be16 qdcount; /* Num of entries in the question section. */
1643 ovs_be16 ancount; /* Num of resource records in the answer section. */
1644
1645 /* Num of name server records in the authority record section. */
1646 ovs_be16 nscount;
1647
1648 /* Num of resource records in the additional records section. */
1649 ovs_be16 arcount;
1650 };
1651
1652 BUILD_ASSERT_DECL(DNS_HEADER_LEN == sizeof(struct dns_header));
1653
1654 #define DNS_QUERY_TYPE_A 0x01
1655 #define DNS_QUERY_TYPE_AAAA 0x1c
1656 #define DNS_QUERY_TYPE_ANY 0xff
1657
1658 #define DNS_CLASS_IN 0x01
1659 #define DNS_DEFAULT_RR_TTL 3600
1660
1661 #endif /* packets.h */