2 * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Nicira, Inc.
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:
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 #include <sys/types.h>
25 #include "openvswitch/geneve.h"
26 #include "openvswitch/packets.h"
27 #include "openvswitch/types.h"
28 #include "odp-netlink.h"
31 #include "tun-metadata.h"
32 #include "unaligned.h"
38 /* Purely internal to OVS userspace. These flags should never be exposed to
39 * the outside world and so aren't included in the flags mask. */
41 /* Tunnel information is in userspace datapath format. */
42 #define FLOW_TNL_F_UDPIF (1 << 4)
44 static inline bool ipv6_addr_is_set(const struct in6_addr
*addr
);
47 flow_tnl_dst_is_set(const struct flow_tnl
*tnl
)
49 return tnl
->ip_dst
|| ipv6_addr_is_set(&tnl
->ipv6_dst
);
52 struct in6_addr
flow_tnl_dst(const struct flow_tnl
*tnl
);
53 struct in6_addr
flow_tnl_src(const struct flow_tnl
*tnl
);
55 /* Returns an offset to 'src' covering all the meaningful fields in 'src'. */
57 flow_tnl_size(const struct flow_tnl
*src
)
59 if (!flow_tnl_dst_is_set(src
)) {
60 /* Covers ip_dst and ipv6_dst only. */
61 return offsetof(struct flow_tnl
, ip_src
);
63 if (src
->flags
& FLOW_TNL_F_UDPIF
) {
64 /* Datapath format, cover all options we have. */
65 return offsetof(struct flow_tnl
, metadata
.opts
)
66 + src
->metadata
.present
.len
;
68 if (!src
->metadata
.present
.map
) {
69 /* No TLVs, opts is irrelevant. */
70 return offsetof(struct flow_tnl
, metadata
.opts
);
72 /* Have decoded TLVs, opts is relevant. */
76 /* Copy flow_tnl, but avoid copying unused portions of tun_metadata. Unused
77 * data in 'dst' is NOT cleared, so this must not be used in cases where the
78 * uninitialized portion may be hashed over. */
80 flow_tnl_copy__(struct flow_tnl
*dst
, const struct flow_tnl
*src
)
82 memcpy(dst
, src
, flow_tnl_size(src
));
86 flow_tnl_equal(const struct flow_tnl
*a
, const struct flow_tnl
*b
)
88 size_t a_size
= flow_tnl_size(a
);
90 return a_size
== flow_tnl_size(b
) && !memcmp(a
, b
, a_size
);
93 /* Datapath packet metadata */
95 uint32_t recirc_id
; /* Recirculation id carried with the
96 recirculating packets. 0 for packets
97 received from the wire. */
98 uint32_t dp_hash
; /* hash value computed by the recirculation
100 uint32_t skb_priority
; /* Packet priority for QoS. */
101 uint32_t pkt_mark
; /* Packet mark. */
102 uint8_t ct_state
; /* Connection state. */
103 bool ct_orig_tuple_ipv6
;
104 uint16_t ct_zone
; /* Connection zone. */
105 uint32_t ct_mark
; /* Connection mark. */
106 ovs_u128 ct_label
; /* Connection label. */
107 union { /* Populated only for non-zero 'ct_state'. */
108 struct ovs_key_ct_tuple_ipv4 ipv4
;
109 struct ovs_key_ct_tuple_ipv6 ipv6
; /* Used only if */
110 } ct_orig_tuple
; /* 'ct_orig_tuple_ipv6' is set */
111 union flow_in_port in_port
; /* Input port. */
112 struct flow_tnl tunnel
; /* Encapsulating tunnel parameters. Note that
113 * if 'ip_dst' == 0, the rest of the fields may
114 * be uninitialized. */
118 pkt_metadata_init_tnl(struct pkt_metadata
*md
)
120 /* Zero up through the tunnel metadata options. The length and table
121 * are before this and as long as they are empty, the options won't
123 memset(md
, 0, offsetof(struct pkt_metadata
, tunnel
.metadata
.opts
));
127 pkt_metadata_init(struct pkt_metadata
*md
, odp_port_t port
)
129 /* It can be expensive to zero out all of the tunnel metadata. However,
130 * we can just zero out ip_dst and the rest of the data will never be
132 memset(md
, 0, offsetof(struct pkt_metadata
, in_port
));
133 md
->tunnel
.ip_dst
= 0;
134 md
->tunnel
.ipv6_dst
= in6addr_any
;
136 md
->in_port
.odp_port
= port
;
139 /* This function prefetches the cachelines touched by pkt_metadata_init()
140 * For performance reasons the two functions should be kept in sync. */
142 pkt_metadata_prefetch_init(struct pkt_metadata
*md
)
144 ovs_prefetch_range(md
, offsetof(struct pkt_metadata
, tunnel
.ip_src
));
147 bool dpid_from_string(const char *s
, uint64_t *dpidp
);
149 #define ETH_ADDR_LEN 6
151 static const struct eth_addr eth_addr_broadcast OVS_UNUSED
152 = { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } } };
154 static const struct eth_addr eth_addr_exact OVS_UNUSED
155 = { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } } };
157 static const struct eth_addr eth_addr_zero OVS_UNUSED
158 = { { { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } };
159 static const struct eth_addr64 eth_addr64_zero OVS_UNUSED
160 = { { { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } };
162 static const struct eth_addr eth_addr_stp OVS_UNUSED
163 = { { { 0x01, 0x80, 0xC2, 0x00, 0x00, 0x00 } } };
165 static const struct eth_addr eth_addr_lacp OVS_UNUSED
166 = { { { 0x01, 0x80, 0xC2, 0x00, 0x00, 0x02 } } };
168 static const struct eth_addr eth_addr_bfd OVS_UNUSED
169 = { { { 0x00, 0x23, 0x20, 0x00, 0x00, 0x01 } } };
171 static inline bool eth_addr_is_broadcast(const struct eth_addr a
)
173 return (a
.be16
[0] & a
.be16
[1] & a
.be16
[2]) == htons(0xffff);
176 static inline bool eth_addr_is_multicast(const struct eth_addr a
)
181 static inline bool eth_addr_is_local(const struct eth_addr a
)
183 /* Local if it is either a locally administered address or a Nicira random
186 || (a
.be16
[0] == htons(0x0023)
187 && (a
.be16
[1] & htons(0xff80)) == htons(0x2080));
189 static inline bool eth_addr_is_zero(const struct eth_addr a
)
191 return !(a
.be16
[0] | a
.be16
[1] | a
.be16
[2]);
193 static inline bool eth_addr64_is_zero(const struct eth_addr64 a
)
195 return !(a
.be16
[0] | a
.be16
[1] | a
.be16
[2] | a
.be16
[3]);
198 static inline int eth_mask_is_exact(const struct eth_addr a
)
200 return (a
.be16
[0] & a
.be16
[1] & a
.be16
[2]) == htons(0xffff);
203 static inline int eth_addr_compare_3way(const struct eth_addr a
,
204 const struct eth_addr b
)
206 return memcmp(&a
, &b
, sizeof a
);
208 static inline int eth_addr64_compare_3way(const struct eth_addr64 a
,
209 const struct eth_addr64 b
)
211 return memcmp(&a
, &b
, sizeof a
);
214 static inline bool eth_addr_equals(const struct eth_addr a
,
215 const struct eth_addr b
)
217 return !eth_addr_compare_3way(a
, b
);
219 static inline bool eth_addr64_equals(const struct eth_addr64 a
,
220 const struct eth_addr64 b
)
222 return !eth_addr64_compare_3way(a
, b
);
225 static inline bool eth_addr_equal_except(const struct eth_addr a
,
226 const struct eth_addr b
,
227 const struct eth_addr mask
)
229 return !(((a
.be16
[0] ^ b
.be16
[0]) & mask
.be16
[0])
230 || ((a
.be16
[1] ^ b
.be16
[1]) & mask
.be16
[1])
231 || ((a
.be16
[2] ^ b
.be16
[2]) & mask
.be16
[2]));
234 static inline uint64_t eth_addr_to_uint64(const struct eth_addr ea
)
236 return (((uint64_t) ntohs(ea
.be16
[0]) << 32)
237 | ((uint64_t) ntohs(ea
.be16
[1]) << 16)
238 | ntohs(ea
.be16
[2]));
241 static inline uint64_t eth_addr_vlan_to_uint64(const struct eth_addr ea
,
244 return (((uint64_t)vlan
<< 48) | eth_addr_to_uint64(ea
));
247 static inline void eth_addr_from_uint64(uint64_t x
, struct eth_addr
*ea
)
249 ea
->be16
[0] = htons(x
>> 32);
250 ea
->be16
[1] = htons((x
& 0xFFFF0000) >> 16);
251 ea
->be16
[2] = htons(x
& 0xFFFF);
254 static inline struct eth_addr
eth_addr_invert(const struct eth_addr src
)
258 for (int i
= 0; i
< ARRAY_SIZE(src
.be16
); i
++) {
259 dst
.be16
[i
] = ~src
.be16
[i
];
265 static inline void eth_addr_mark_random(struct eth_addr
*ea
)
267 ea
->ea
[0] &= ~1; /* Unicast. */
268 ea
->ea
[0] |= 2; /* Private. */
271 static inline void eth_addr_random(struct eth_addr
*ea
)
273 random_bytes((uint8_t *)ea
, sizeof *ea
);
274 eth_addr_mark_random(ea
);
277 static inline void eth_addr_nicira_random(struct eth_addr
*ea
)
281 /* Set the OUI to the Nicira one. */
286 /* Set the top bit to indicate random Nicira address. */
289 static inline uint32_t hash_mac(const struct eth_addr ea
,
290 const uint16_t vlan
, const uint32_t basis
)
292 return hash_uint64_basis(eth_addr_vlan_to_uint64(ea
, vlan
), basis
);
295 bool eth_addr_is_reserved(const struct eth_addr
);
296 bool eth_addr_from_string(const char *, struct eth_addr
*);
298 void compose_rarp(struct dp_packet
*, const struct eth_addr
);
300 void eth_push_vlan(struct dp_packet
*, ovs_be16 tpid
, ovs_be16 tci
);
301 void eth_pop_vlan(struct dp_packet
*);
303 const char *eth_from_hex(const char *hex
, struct dp_packet
**packetp
);
304 void eth_format_masked(const struct eth_addr ea
,
305 const struct eth_addr
*mask
, struct ds
*s
);
307 void set_mpls_lse(struct dp_packet
*, ovs_be32 label
);
308 void push_mpls(struct dp_packet
*packet
, ovs_be16 ethtype
, ovs_be32 lse
);
309 void pop_mpls(struct dp_packet
*, ovs_be16 ethtype
);
311 void set_mpls_lse_ttl(ovs_be32
*lse
, uint8_t ttl
);
312 void set_mpls_lse_tc(ovs_be32
*lse
, uint8_t tc
);
313 void set_mpls_lse_label(ovs_be32
*lse
, ovs_be32 label
);
314 void set_mpls_lse_bos(ovs_be32
*lse
, uint8_t bos
);
315 ovs_be32
set_mpls_lse_values(uint8_t ttl
, uint8_t tc
, uint8_t bos
,
320 * struct eth_addr mac;
322 * printf("The Ethernet address is "ETH_ADDR_FMT"\n", ETH_ADDR_ARGS(mac));
325 #define ETH_ADDR_FMT \
326 "%02"PRIx8":%02"PRIx8":%02"PRIx8":%02"PRIx8":%02"PRIx8":%02"PRIx8
327 #define ETH_ADDR_ARGS(EA) ETH_ADDR_BYTES_ARGS((EA).ea)
328 #define ETH_ADDR_BYTES_ARGS(EAB) \
329 (EAB)[0], (EAB)[1], (EAB)[2], (EAB)[3], (EAB)[4], (EAB)[5]
330 #define ETH_ADDR_STRLEN 17
334 * struct eth_addr64 eui64;
336 * printf("The EUI-64 address is "ETH_ADDR64_FMT"\n", ETH_ADDR64_ARGS(mac));
339 #define ETH_ADDR64_FMT \
340 "%02"PRIx8":%02"PRIx8":%02"PRIx8":%02"PRIx8":" \
341 "%02"PRIx8":%02"PRIx8":%02"PRIx8":%02"PRIx8
342 #define ETH_ADDR64_ARGS(EA) ETH_ADDR64_BYTES_ARGS((EA).ea64)
343 #define ETH_ADDR64_BYTES_ARGS(EAB) \
344 (EAB)[0], (EAB)[1], (EAB)[2], (EAB)[3], \
345 (EAB)[4], (EAB)[5], (EAB)[6], (EAB)[7]
346 #define ETH_ADDR64_STRLEN 23
350 * char *string = "1 00:11:22:33:44:55 2";
351 * struct eth_addr mac;
354 * if (ovs_scan(string, "%d"ETH_ADDR_SCAN_FMT"%d",
355 * &a, ETH_ADDR_SCAN_ARGS(mac), &b)) {
359 #define ETH_ADDR_SCAN_FMT "%"SCNx8":%"SCNx8":%"SCNx8":%"SCNx8":%"SCNx8":%"SCNx8
360 #define ETH_ADDR_SCAN_ARGS(EA) \
361 &(EA).ea[0], &(EA).ea[1], &(EA).ea[2], &(EA).ea[3], &(EA).ea[4], &(EA).ea[5]
363 #define ETH_TYPE_IP 0x0800
364 #define ETH_TYPE_ARP 0x0806
365 #define ETH_TYPE_TEB 0x6558
366 #define ETH_TYPE_VLAN_8021Q 0x8100
367 #define ETH_TYPE_VLAN ETH_TYPE_VLAN_8021Q
368 #define ETH_TYPE_VLAN_8021AD 0x88a8
369 #define ETH_TYPE_IPV6 0x86dd
370 #define ETH_TYPE_LACP 0x8809
371 #define ETH_TYPE_RARP 0x8035
372 #define ETH_TYPE_MPLS 0x8847
373 #define ETH_TYPE_MPLS_MCAST 0x8848
375 static inline bool eth_type_mpls(ovs_be16 eth_type
)
377 return eth_type
== htons(ETH_TYPE_MPLS
) ||
378 eth_type
== htons(ETH_TYPE_MPLS_MCAST
);
381 static inline bool eth_type_vlan(ovs_be16 eth_type
)
383 return eth_type
== htons(ETH_TYPE_VLAN_8021Q
) ||
384 eth_type
== htons(ETH_TYPE_VLAN_8021AD
);
388 /* Minimum value for an Ethernet type. Values below this are IEEE 802.2 frame
390 #define ETH_TYPE_MIN 0x600
392 #define ETH_HEADER_LEN 14
393 #define ETH_PAYLOAD_MIN 46
394 #define ETH_PAYLOAD_MAX 1500
395 #define ETH_TOTAL_MIN (ETH_HEADER_LEN + ETH_PAYLOAD_MIN)
396 #define ETH_TOTAL_MAX (ETH_HEADER_LEN + ETH_PAYLOAD_MAX)
397 #define ETH_VLAN_TOTAL_MAX (ETH_HEADER_LEN + VLAN_HEADER_LEN + ETH_PAYLOAD_MAX)
400 struct eth_addr eth_dst
;
401 struct eth_addr eth_src
;
404 BUILD_ASSERT_DECL(ETH_HEADER_LEN
== sizeof(struct eth_header
));
406 void push_eth(struct dp_packet
*packet
, const struct eth_addr
*dst
,
407 const struct eth_addr
*src
);
408 void pop_eth(struct dp_packet
*packet
);
410 #define LLC_DSAP_SNAP 0xaa
411 #define LLC_SSAP_SNAP 0xaa
412 #define LLC_CNTL_SNAP 3
414 #define LLC_HEADER_LEN 3
421 BUILD_ASSERT_DECL(LLC_HEADER_LEN
== sizeof(struct llc_header
));
423 /* LLC field values used for STP frames. */
424 #define STP_LLC_SSAP 0x42
425 #define STP_LLC_DSAP 0x42
426 #define STP_LLC_CNTL 0x03
428 #define SNAP_ORG_ETHERNET "\0\0" /* The compiler adds a null byte, so
429 sizeof(SNAP_ORG_ETHERNET) == 3. */
430 #define SNAP_HEADER_LEN 5
436 BUILD_ASSERT_DECL(SNAP_HEADER_LEN
== sizeof(struct snap_header
));
438 #define LLC_SNAP_HEADER_LEN (LLC_HEADER_LEN + SNAP_HEADER_LEN)
440 struct llc_snap_header
{
441 struct llc_header llc
;
442 struct snap_header snap
;
444 BUILD_ASSERT_DECL(LLC_SNAP_HEADER_LEN
== sizeof(struct llc_snap_header
));
446 #define VLAN_VID_MASK 0x0fff
447 #define VLAN_VID_SHIFT 0
449 #define VLAN_PCP_MASK 0xe000
450 #define VLAN_PCP_SHIFT 13
452 #define VLAN_CFI 0x1000
453 #define VLAN_CFI_SHIFT 12
455 /* Given the vlan_tci field from an 802.1Q header, in network byte order,
456 * returns the VLAN ID in host byte order. */
457 static inline uint16_t
458 vlan_tci_to_vid(ovs_be16 vlan_tci
)
460 return (ntohs(vlan_tci
) & VLAN_VID_MASK
) >> VLAN_VID_SHIFT
;
463 /* Given the vlan_tci field from an 802.1Q header, in network byte order,
464 * returns the priority code point (PCP) in host byte order. */
466 vlan_tci_to_pcp(ovs_be16 vlan_tci
)
468 return (ntohs(vlan_tci
) & VLAN_PCP_MASK
) >> VLAN_PCP_SHIFT
;
471 /* Given the vlan_tci field from an 802.1Q header, in network byte order,
472 * returns the Canonical Format Indicator (CFI). */
474 vlan_tci_to_cfi(ovs_be16 vlan_tci
)
476 return (vlan_tci
& htons(VLAN_CFI
)) != 0;
479 #define VLAN_HEADER_LEN 4
481 ovs_be16 vlan_tci
; /* Lowest 12 bits are VLAN ID. */
482 ovs_be16 vlan_next_type
;
484 BUILD_ASSERT_DECL(VLAN_HEADER_LEN
== sizeof(struct vlan_header
));
486 #define VLAN_ETH_HEADER_LEN (ETH_HEADER_LEN + VLAN_HEADER_LEN)
488 struct vlan_eth_header
{
489 struct eth_addr veth_dst
;
490 struct eth_addr veth_src
;
491 ovs_be16 veth_type
; /* Always htons(ETH_TYPE_VLAN). */
492 ovs_be16 veth_tci
; /* Lowest 12 bits are VLAN ID. */
493 ovs_be16 veth_next_type
;
495 BUILD_ASSERT_DECL(VLAN_ETH_HEADER_LEN
== sizeof(struct vlan_eth_header
));
497 /* MPLS related definitions */
498 #define MPLS_TTL_MASK 0x000000ff
499 #define MPLS_TTL_SHIFT 0
501 #define MPLS_BOS_MASK 0x00000100
502 #define MPLS_BOS_SHIFT 8
504 #define MPLS_TC_MASK 0x00000e00
505 #define MPLS_TC_SHIFT 9
507 #define MPLS_LABEL_MASK 0xfffff000
508 #define MPLS_LABEL_SHIFT 12
513 ovs_16aligned_be32 mpls_lse
;
515 BUILD_ASSERT_DECL(MPLS_HLEN
== sizeof(struct mpls_hdr
));
517 /* Given a mpls label stack entry in network byte order
518 * return mpls label in host byte order */
519 static inline uint32_t
520 mpls_lse_to_label(ovs_be32 mpls_lse
)
522 return (ntohl(mpls_lse
) & MPLS_LABEL_MASK
) >> MPLS_LABEL_SHIFT
;
525 /* Given a mpls label stack entry in network byte order
527 static inline uint8_t
528 mpls_lse_to_tc(ovs_be32 mpls_lse
)
530 return (ntohl(mpls_lse
) & MPLS_TC_MASK
) >> MPLS_TC_SHIFT
;
533 /* Given a mpls label stack entry in network byte order
535 static inline uint8_t
536 mpls_lse_to_ttl(ovs_be32 mpls_lse
)
538 return (ntohl(mpls_lse
) & MPLS_TTL_MASK
) >> MPLS_TTL_SHIFT
;
541 /* Set TTL in mpls lse. */
543 flow_set_mpls_lse_ttl(ovs_be32
*mpls_lse
, uint8_t ttl
)
545 *mpls_lse
&= ~htonl(MPLS_TTL_MASK
);
546 *mpls_lse
|= htonl(ttl
<< MPLS_TTL_SHIFT
);
549 /* Given a mpls label stack entry in network byte order
550 * return mpls BoS bit */
551 static inline uint8_t
552 mpls_lse_to_bos(ovs_be32 mpls_lse
)
554 return (mpls_lse
& htonl(MPLS_BOS_MASK
)) != 0;
557 #define IP_FMT "%"PRIu32".%"PRIu32".%"PRIu32".%"PRIu32
558 #define IP_ARGS(ip) \
560 (ntohl(ip) >> 16) & 0xff, \
561 (ntohl(ip) >> 8) & 0xff, \
566 * char *string = "1 33.44.55.66 2";
570 * if (ovs_scan(string, "%d"IP_SCAN_FMT"%d", &a, IP_SCAN_ARGS(&ip), &b)) {
574 #define IP_SCAN_FMT "%"SCNu8".%"SCNu8".%"SCNu8".%"SCNu8
575 #define IP_SCAN_ARGS(ip) \
576 ((void) (ovs_be32) *(ip), &((uint8_t *) ip)[0]), \
577 &((uint8_t *) ip)[1], \
578 &((uint8_t *) ip)[2], \
581 #define IP_PORT_SCAN_FMT "%"SCNu8".%"SCNu8".%"SCNu8".%"SCNu8":%"SCNu16
582 #define IP_PORT_SCAN_ARGS(ip, port) \
583 ((void) (ovs_be32) *(ip), &((uint8_t *) ip)[0]), \
584 &((uint8_t *) ip)[1], \
585 &((uint8_t *) ip)[2], \
586 &((uint8_t *) ip)[3], \
587 ((void) (ovs_be16) *(port), (uint16_t *) port)
589 /* Returns true if 'netmask' is a CIDR netmask, that is, if it consists of N
590 * high-order 1-bits and 32-N low-order 0-bits. */
592 ip_is_cidr(ovs_be32 netmask
)
594 uint32_t x
= ~ntohl(netmask
);
595 return !(x
& (x
+ 1));
598 ip_is_multicast(ovs_be32 ip
)
600 return (ip
& htonl(0xf0000000)) == htonl(0xe0000000);
603 ip_is_local_multicast(ovs_be32 ip
)
605 return (ip
& htonl(0xffffff00)) == htonl(0xe0000000);
607 int ip_count_cidr_bits(ovs_be32 netmask
);
608 void ip_format_masked(ovs_be32 ip
, ovs_be32 mask
, struct ds
*);
609 bool ip_parse(const char *s
, ovs_be32
*ip
);
610 char *ip_parse_port(const char *s
, ovs_be32
*ip
, ovs_be16
*port
)
611 OVS_WARN_UNUSED_RESULT
;
612 char *ip_parse_masked(const char *s
, ovs_be32
*ip
, ovs_be32
*mask
)
613 OVS_WARN_UNUSED_RESULT
;
614 char *ip_parse_cidr(const char *s
, ovs_be32
*ip
, unsigned int *plen
)
615 OVS_WARN_UNUSED_RESULT
;
616 char *ip_parse_masked_len(const char *s
, int *n
, ovs_be32
*ip
, ovs_be32
*mask
)
617 OVS_WARN_UNUSED_RESULT
;
618 char *ip_parse_cidr_len(const char *s
, int *n
, ovs_be32
*ip
,
620 OVS_WARN_UNUSED_RESULT
;
622 #define IP_VER(ip_ihl_ver) ((ip_ihl_ver) >> 4)
623 #define IP_IHL(ip_ihl_ver) ((ip_ihl_ver) & 15)
624 #define IP_IHL_VER(ihl, ver) (((ver) << 4) | (ihl))
627 #define IPPROTO_SCTP 132
631 #define IPPROTO_DCCP 33
635 #define IPPROTO_IGMP 2
638 #ifndef IPPROTO_UDPLITE
639 #define IPPROTO_UDPLITE 136
643 #define IP_ECN_NOT_ECT 0x0
644 #define IP_ECN_ECT_1 0x01
645 #define IP_ECN_ECT_0 0x02
646 #define IP_ECN_CE 0x03
647 #define IP_ECN_MASK 0x03
648 #define IP_DSCP_MASK 0xfc
651 IP_ECN_is_ce(uint8_t dsfield
)
653 return (dsfield
& IP_ECN_MASK
) == IP_ECN_CE
;
658 #define IP_DONT_FRAGMENT 0x4000 /* Don't fragment. */
659 #define IP_MORE_FRAGMENTS 0x2000 /* More fragments. */
660 #define IP_FRAG_OFF_MASK 0x1fff /* Fragment offset. */
661 #define IP_IS_FRAGMENT(ip_frag_off) \
662 ((ip_frag_off) & htons(IP_MORE_FRAGMENTS | IP_FRAG_OFF_MASK))
664 #define IP_HEADER_LEN 20
670 ovs_be16 ip_frag_off
;
674 ovs_16aligned_be32 ip_src
;
675 ovs_16aligned_be32 ip_dst
;
677 BUILD_ASSERT_DECL(IP_HEADER_LEN
== sizeof(struct ip_header
));
680 #define ICMP4_ECHO_REPLY 0
681 #define ICMP4_DST_UNREACH 3
682 #define ICMP4_SOURCEQUENCH 4
683 #define ICMP4_REDIRECT 5
684 #define ICMP4_ECHO_REQUEST 8
685 #define ICMP4_TIME_EXCEEDED 11
686 #define ICMP4_PARAM_PROB 12
687 #define ICMP4_TIMESTAMP 13
688 #define ICMP4_TIMESTAMPREPLY 14
689 #define ICMP4_INFOREQUEST 15
690 #define ICMP4_INFOREPLY 16
692 #define ICMP_HEADER_LEN 8
706 ovs_16aligned_be32 gateway
;
709 BUILD_ASSERT_DECL(ICMP_HEADER_LEN
== sizeof(struct icmp_header
));
711 #define IGMP_HEADER_LEN 8
716 ovs_16aligned_be32 group
;
718 BUILD_ASSERT_DECL(IGMP_HEADER_LEN
== sizeof(struct igmp_header
));
720 #define IGMPV3_HEADER_LEN 8
721 struct igmpv3_header
{
728 BUILD_ASSERT_DECL(IGMPV3_HEADER_LEN
== sizeof(struct igmpv3_header
));
730 #define IGMPV3_RECORD_LEN 8
731 struct igmpv3_record
{
735 ovs_16aligned_be32 maddr
;
737 BUILD_ASSERT_DECL(IGMPV3_RECORD_LEN
== sizeof(struct igmpv3_record
));
739 #define IGMP_HOST_MEMBERSHIP_QUERY 0x11 /* From RFC1112 */
740 #define IGMP_HOST_MEMBERSHIP_REPORT 0x12 /* Ditto */
741 #define IGMPV2_HOST_MEMBERSHIP_REPORT 0x16 /* V2 version of 0x12 */
742 #define IGMP_HOST_LEAVE_MESSAGE 0x17
743 #define IGMPV3_HOST_MEMBERSHIP_REPORT 0x22 /* V3 version of 0x12 */
746 * IGMPv3 and MLDv2 use the same codes.
748 #define IGMPV3_MODE_IS_INCLUDE 1
749 #define IGMPV3_MODE_IS_EXCLUDE 2
750 #define IGMPV3_CHANGE_TO_INCLUDE_MODE 3
751 #define IGMPV3_CHANGE_TO_EXCLUDE_MODE 4
752 #define IGMPV3_ALLOW_NEW_SOURCES 5
753 #define IGMPV3_BLOCK_OLD_SOURCES 6
755 #define SCTP_HEADER_LEN 12
759 ovs_16aligned_be32 sctp_vtag
;
760 ovs_16aligned_be32 sctp_csum
;
762 BUILD_ASSERT_DECL(SCTP_HEADER_LEN
== sizeof(struct sctp_header
));
764 #define UDP_HEADER_LEN 8
771 BUILD_ASSERT_DECL(UDP_HEADER_LEN
== sizeof(struct udp_header
));
773 #define TCP_FIN 0x001
774 #define TCP_SYN 0x002
775 #define TCP_RST 0x004
776 #define TCP_PSH 0x008
777 #define TCP_ACK 0x010
778 #define TCP_URG 0x020
779 #define TCP_ECE 0x040
780 #define TCP_CWR 0x080
783 #define TCP_CTL(flags, offset) (htons((flags) | ((offset) << 12)))
784 #define TCP_FLAGS(tcp_ctl) (ntohs(tcp_ctl) & 0x0fff)
785 #define TCP_FLAGS_BE16(tcp_ctl) ((tcp_ctl) & htons(0x0fff))
786 #define TCP_OFFSET(tcp_ctl) (ntohs(tcp_ctl) >> 12)
788 #define TCP_HEADER_LEN 20
792 ovs_16aligned_be32 tcp_seq
;
793 ovs_16aligned_be32 tcp_ack
;
799 BUILD_ASSERT_DECL(TCP_HEADER_LEN
== sizeof(struct tcp_header
));
801 /* Connection states.
803 * Names like CS_RELATED are bit values, e.g. 1 << 2.
804 * Names like CS_RELATED_BIT are bit indexes, e.g. 2. */
806 CS_STATE(NEW, 0, "new") \
807 CS_STATE(ESTABLISHED, 1, "est") \
808 CS_STATE(RELATED, 2, "rel") \
809 CS_STATE(REPLY_DIR, 3, "rpl") \
810 CS_STATE(INVALID, 4, "inv") \
811 CS_STATE(TRACKED, 5, "trk") \
812 CS_STATE(SRC_NAT, 6, "snat") \
813 CS_STATE(DST_NAT, 7, "dnat")
816 #define CS_STATE(ENUM, INDEX, NAME) \
817 CS_##ENUM = 1 << INDEX, \
818 CS_##ENUM##_BIT = INDEX,
823 /* Undefined connection state bits. */
825 #define CS_STATE(ENUM, INDEX, NAME) +CS_##ENUM
826 CS_SUPPORTED_MASK
= CS_STATES
829 #define CS_UNSUPPORTED_MASK (~(uint32_t)CS_SUPPORTED_MASK)
831 #define ARP_HRD_ETHERNET 1
832 #define ARP_PRO_IP 0x0800
833 #define ARP_OP_REQUEST 1
834 #define ARP_OP_REPLY 2
835 #define ARP_OP_RARP 3
837 #define ARP_ETH_HEADER_LEN 28
838 struct arp_eth_header
{
839 /* Generic members. */
840 ovs_be16 ar_hrd
; /* Hardware type. */
841 ovs_be16 ar_pro
; /* Protocol type. */
842 uint8_t ar_hln
; /* Hardware address length. */
843 uint8_t ar_pln
; /* Protocol address length. */
844 ovs_be16 ar_op
; /* Opcode. */
846 /* Ethernet+IPv4 specific members. */
847 struct eth_addr ar_sha
; /* Sender hardware address. */
848 ovs_16aligned_be32 ar_spa
; /* Sender protocol address. */
849 struct eth_addr ar_tha
; /* Target hardware address. */
850 ovs_16aligned_be32 ar_tpa
; /* Target protocol address. */
852 BUILD_ASSERT_DECL(ARP_ETH_HEADER_LEN
== sizeof(struct arp_eth_header
));
854 #define IPV6_HEADER_LEN 40
856 /* Like struct in6_addr, but whereas that struct requires 32-bit alignment on
857 * most implementations, this one only requires 16-bit alignment. */
858 union ovs_16aligned_in6_addr
{
860 ovs_16aligned_be32 be32
[4];
863 /* Like struct in6_hdr, but whereas that struct requires 32-bit alignment, this
864 * one only requires 16-bit alignment. */
865 struct ovs_16aligned_ip6_hdr
{
867 struct ovs_16aligned_ip6_hdrctl
{
868 ovs_16aligned_be32 ip6_un1_flow
;
869 ovs_be16 ip6_un1_plen
;
871 uint8_t ip6_un1_hlim
;
875 union ovs_16aligned_in6_addr ip6_src
;
876 union ovs_16aligned_in6_addr ip6_dst
;
879 /* Like struct in6_frag, but whereas that struct requires 32-bit alignment,
880 * this one only requires 16-bit alignment. */
881 struct ovs_16aligned_ip6_frag
{
883 uint8_t ip6f_reserved
;
885 ovs_16aligned_be32 ip6f_ident
;
888 #define ICMP6_HEADER_LEN 4
889 struct icmp6_header
{
892 ovs_be16 icmp6_cksum
;
894 BUILD_ASSERT_DECL(ICMP6_HEADER_LEN
== sizeof(struct icmp6_header
));
896 uint32_t packet_csum_pseudoheader6(const struct ovs_16aligned_ip6_hdr
*);
897 uint16_t packet_csum_upperlayer6(const struct ovs_16aligned_ip6_hdr
*,
898 const void *, uint8_t, uint16_t);
900 /* Neighbor Discovery option field.
901 * ND options are always a multiple of 8 bytes in size. */
902 #define ND_LLA_OPT_LEN 8
903 struct ovs_nd_lla_opt
{
904 uint8_t type
; /* One of ND_OPT_*_LINKADDR. */
908 BUILD_ASSERT_DECL(ND_LLA_OPT_LEN
== sizeof(struct ovs_nd_lla_opt
));
910 /* Neighbor Discovery option: Prefix Information. */
911 #define ND_PREFIX_OPT_LEN 32
912 struct ovs_nd_prefix_opt
{
913 uint8_t type
; /* ND_OPT_PREFIX_INFORMATION. */
914 uint8_t len
; /* Always 4. */
916 uint8_t la_flags
; /* ND_PREFIX_* flags. */
917 ovs_16aligned_be32 valid_lifetime
;
918 ovs_16aligned_be32 preferred_lifetime
;
919 ovs_16aligned_be32 reserved
; /* Always 0. */
920 union ovs_16aligned_in6_addr prefix
;
922 BUILD_ASSERT_DECL(ND_PREFIX_OPT_LEN
== sizeof(struct ovs_nd_prefix_opt
));
924 #define ND_PREFIX_ON_LINK 0x80
925 #define ND_PREFIX_AUTONOMOUS_ADDRESS 0x40
927 /* Neighbor Discovery option: MTU. */
928 #define ND_MTU_OPT_LEN 8
929 struct ovs_nd_mtu_opt
{
930 uint8_t type
; /* ND_OPT_MTU */
931 uint8_t len
; /* Always 1. */
932 ovs_be16 reserved
; /* Always 0. */
933 ovs_16aligned_be32 mtu
;
935 BUILD_ASSERT_DECL(ND_MTU_OPT_LEN
== sizeof(struct ovs_nd_mtu_opt
));
937 /* Like struct nd_msg (from ndisc.h), but whereas that struct requires 32-bit
938 * alignment, this one only requires 16-bit alignment. */
939 #define ND_MSG_LEN 24
941 struct icmp6_header icmph
;
942 ovs_16aligned_be32 rso_flags
;
943 union ovs_16aligned_in6_addr target
;
944 struct ovs_nd_lla_opt options
[0];
946 BUILD_ASSERT_DECL(ND_MSG_LEN
== sizeof(struct ovs_nd_msg
));
948 /* Neighbor Discovery packet flags. */
949 #define ND_RSO_ROUTER 0x80000000
950 #define ND_RSO_SOLICITED 0x40000000
951 #define ND_RSO_OVERRIDE 0x20000000
953 #define RA_MSG_LEN 16
955 struct icmp6_header icmph
;
956 uint8_t cur_hop_limit
;
957 uint8_t mo_flags
; /* ND_RA_MANAGED_ADDRESS and ND_RA_OTHER_CONFIG flags. */
958 ovs_be16 router_lifetime
;
959 ovs_be32 reachable_time
;
960 ovs_be32 retrans_timer
;
961 struct ovs_nd_lla_opt options
[0];
963 BUILD_ASSERT_DECL(RA_MSG_LEN
== sizeof(struct ovs_ra_msg
));
965 #define ND_RA_MANAGED_ADDRESS 0x80
966 #define ND_RA_OTHER_CONFIG 0x40
969 * Use the same struct for MLD and MLD2, naming members as the defined fields in
970 * in the corresponding version of the protocol, though they are reserved in the
973 #define MLD_HEADER_LEN 8
981 BUILD_ASSERT_DECL(MLD_HEADER_LEN
== sizeof(struct mld_header
));
983 #define MLD2_RECORD_LEN 20
988 union ovs_16aligned_in6_addr maddr
;
990 BUILD_ASSERT_DECL(MLD2_RECORD_LEN
== sizeof(struct mld2_record
));
992 #define MLD_QUERY 130
993 #define MLD_REPORT 131
995 #define MLD2_REPORT 143
997 /* The IPv6 flow label is in the lower 20 bits of the first 32-bit word. */
998 #define IPV6_LABEL_MASK 0x000fffff
1002 * char *string = "1 ::1 2";
1003 * char ipv6_s[IPV6_SCAN_LEN + 1];
1004 * struct in6_addr ipv6;
1006 * if (ovs_scan(string, "%d"IPV6_SCAN_FMT"%d", &a, ipv6_s, &b)
1007 * && inet_pton(AF_INET6, ipv6_s, &ipv6) == 1) {
1011 #define IPV6_SCAN_FMT "%46[0123456789abcdefABCDEF:.]"
1012 #define IPV6_SCAN_LEN 46
1014 extern const struct in6_addr in6addr_exact
;
1015 #define IN6ADDR_EXACT_INIT { { { 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, \
1016 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff } } }
1018 extern const struct in6_addr in6addr_all_hosts
;
1019 #define IN6ADDR_ALL_HOSTS_INIT { { { 0xff,0x02,0x00,0x00,0x00,0x00,0x00,0x00, \
1020 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01 } } }
1022 extern const struct in6_addr in6addr_all_routers
;
1023 #define IN6ADDR_ALL_ROUTERS_INIT { { { 0xff,0x02,0x00,0x00,0x00,0x00,0x00,0x00, \
1024 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02 } } }
1026 static inline bool ipv6_addr_equals(const struct in6_addr
*a
,
1027 const struct in6_addr
*b
)
1029 #ifdef IN6_ARE_ADDR_EQUAL
1030 return IN6_ARE_ADDR_EQUAL(a
, b
);
1032 return !memcmp(a
, b
, sizeof(*a
));
1036 /* Checks the IPv6 address in 'mask' for all zeroes. */
1037 static inline bool ipv6_mask_is_any(const struct in6_addr
*mask
) {
1038 return ipv6_addr_equals(mask
, &in6addr_any
);
1041 static inline bool ipv6_mask_is_exact(const struct in6_addr
*mask
) {
1042 return ipv6_addr_equals(mask
, &in6addr_exact
);
1045 static inline bool ipv6_is_all_hosts(const struct in6_addr
*addr
) {
1046 return ipv6_addr_equals(addr
, &in6addr_all_hosts
);
1049 static inline bool ipv6_addr_is_set(const struct in6_addr
*addr
) {
1050 return !ipv6_addr_equals(addr
, &in6addr_any
);
1053 static inline bool ipv6_addr_is_multicast(const struct in6_addr
*ip
) {
1054 return ip
->s6_addr
[0] == 0xff;
1057 static inline struct in6_addr
1058 in6_addr_mapped_ipv4(ovs_be32 ip4
)
1060 struct in6_addr ip6
= { .s6_addr
= { [10] = 0xff, [11] = 0xff } };
1061 memcpy(&ip6
.s6_addr
[12], &ip4
, 4);
1066 in6_addr_set_mapped_ipv4(struct in6_addr
*ip6
, ovs_be32 ip4
)
1068 *ip6
= in6_addr_mapped_ipv4(ip4
);
1071 static inline ovs_be32
1072 in6_addr_get_mapped_ipv4(const struct in6_addr
*addr
)
1074 union ovs_16aligned_in6_addr
*taddr
= (void *) addr
;
1075 if (IN6_IS_ADDR_V4MAPPED(addr
)) {
1076 return get_16aligned_be32(&taddr
->be32
[3]);
1083 in6_addr_solicited_node(struct in6_addr
*addr
, const struct in6_addr
*ip6
)
1085 union ovs_16aligned_in6_addr
*taddr
= (void *) addr
;
1086 memset(taddr
->be16
, 0, sizeof(taddr
->be16
));
1087 taddr
->be16
[0] = htons(0xff02);
1088 taddr
->be16
[5] = htons(0x1);
1089 taddr
->be16
[6] = htons(0xff00);
1090 memcpy(&addr
->s6_addr
[13], &ip6
->s6_addr
[13], 3);
1094 * Generates ipv6 EUI64 address from the given eth addr
1095 * and prefix and stores it in 'lla'
1098 in6_generate_eui64(struct eth_addr ea
, struct in6_addr
*prefix
,
1099 struct in6_addr
*lla
)
1101 union ovs_16aligned_in6_addr
*taddr
= (void *) lla
;
1102 union ovs_16aligned_in6_addr
*prefix_taddr
= (void *) prefix
;
1103 taddr
->be16
[0] = prefix_taddr
->be16
[0];
1104 taddr
->be16
[1] = prefix_taddr
->be16
[1];
1105 taddr
->be16
[2] = prefix_taddr
->be16
[2];
1106 taddr
->be16
[3] = prefix_taddr
->be16
[3];
1107 taddr
->be16
[4] = htons(((ea
.ea
[0] ^ 0x02) << 8) | ea
.ea
[1]);
1108 taddr
->be16
[5] = htons(ea
.ea
[2] << 8 | 0x00ff);
1109 taddr
->be16
[6] = htons(0xfe << 8 | ea
.ea
[3]);
1110 taddr
->be16
[7] = ea
.be16
[2];
1114 * Generates ipv6 link local address from the given eth addr
1115 * with prefix 'fe80::/64' and stores it in 'lla'
1118 in6_generate_lla(struct eth_addr ea
, struct in6_addr
*lla
)
1120 union ovs_16aligned_in6_addr
*taddr
= (void *) lla
;
1121 memset(taddr
->be16
, 0, sizeof(taddr
->be16
));
1122 taddr
->be16
[0] = htons(0xfe80);
1123 taddr
->be16
[4] = htons(((ea
.ea
[0] ^ 0x02) << 8) | ea
.ea
[1]);
1124 taddr
->be16
[5] = htons(ea
.ea
[2] << 8 | 0x00ff);
1125 taddr
->be16
[6] = htons(0xfe << 8 | ea
.ea
[3]);
1126 taddr
->be16
[7] = ea
.be16
[2];
1129 /* Returns true if 'addr' is a link local address. Otherwise, false. */
1131 in6_is_lla(struct in6_addr
*addr
)
1134 return addr
->s6_addr32
[0] == htonl(0xfe800000) && !(addr
->s6_addr32
[1]);
1136 return addr
->s6_addr
[0] == 0xfe && addr
->s6_addr
[1] == 0x80 &&
1137 !(addr
->s6_addr
[2] | addr
->s6_addr
[3] | addr
->s6_addr
[4] |
1138 addr
->s6_addr
[5] | addr
->s6_addr
[6] | addr
->s6_addr
[7]);
1143 ipv6_multicast_to_ethernet(struct eth_addr
*eth
, const struct in6_addr
*ip6
)
1147 eth
->ea
[2] = ip6
->s6_addr
[12];
1148 eth
->ea
[3] = ip6
->s6_addr
[13];
1149 eth
->ea
[4] = ip6
->s6_addr
[14];
1150 eth
->ea
[5] = ip6
->s6_addr
[15];
1153 static inline bool dl_type_is_ip_any(ovs_be16 dl_type
)
1155 return dl_type
== htons(ETH_TYPE_IP
)
1156 || dl_type
== htons(ETH_TYPE_IPV6
);
1161 /* GRE protocol header */
1162 struct gre_base_hdr
{
1167 #define GRE_CSUM 0x8000
1168 #define GRE_ROUTING 0x4000
1169 #define GRE_KEY 0x2000
1170 #define GRE_SEQ 0x1000
1171 #define GRE_STRICT 0x0800
1172 #define GRE_REC 0x0700
1173 #define GRE_FLAGS 0x00F8
1174 #define GRE_VERSION 0x0007
1176 /* VXLAN protocol header */
1178 ovs_16aligned_be32 vx_flags
;
1179 ovs_16aligned_be32 vx_vni
;
1182 #define VXLAN_FLAGS 0x08000000 /* struct vxlanhdr.vx_flags required value. */
1184 /* Input values for PACKET_TYPE macros have to be in host byte order.
1185 * The _BE postfix indicates result is in network byte order. Otherwise result
1186 * is in host byte order. */
1187 #define PACKET_TYPE(NS, NS_TYPE) ((uint32_t) ((NS) << 16 | (NS_TYPE)))
1188 #define PACKET_TYPE_BE(NS, NS_TYPE) (htonl((NS) << 16 | (NS_TYPE)))
1190 /* Returns the host byte ordered namespace of 'packet type'. */
1191 static inline uint16_t
1192 pt_ns(ovs_be32 packet_type
)
1194 return ntohl(packet_type
) >> 16;
1197 /* Returns the network byte ordered namespace type of 'packet type'. */
1198 static inline ovs_be16
1199 pt_ns_type_be(ovs_be32 packet_type
)
1201 return be32_to_be16(packet_type
);
1204 /* Returns the host byte ordered namespace type of 'packet type'. */
1205 static inline uint16_t
1206 pt_ns_type(ovs_be32 packet_type
)
1208 return ntohs(pt_ns_type_be(packet_type
));
1211 /* Well-known packet_type field values. */
1213 PT_ETH
= PACKET_TYPE(OFPHTN_ONF
, 0x0000), /* Default: Ethernet */
1214 PT_IPV4
= PACKET_TYPE(OFPHTN_ETHERTYPE
, ETH_TYPE_IP
),
1215 PT_IPV6
= PACKET_TYPE(OFPHTN_ETHERTYPE
, ETH_TYPE_IPV6
),
1216 PT_MPLS
= PACKET_TYPE(OFPHTN_ETHERTYPE
, ETH_TYPE_MPLS
),
1217 PT_MPLS_MC
= PACKET_TYPE(OFPHTN_ETHERTYPE
, ETH_TYPE_MPLS_MCAST
),
1218 PT_UNKNOWN
= PACKET_TYPE(0xffff, 0xffff), /* Unknown packet type. */
1222 void ipv6_format_addr(const struct in6_addr
*addr
, struct ds
*);
1223 void ipv6_format_addr_bracket(const struct in6_addr
*addr
, struct ds
*,
1225 void ipv6_format_mapped(const struct in6_addr
*addr
, struct ds
*);
1226 void ipv6_format_masked(const struct in6_addr
*addr
,
1227 const struct in6_addr
*mask
, struct ds
*);
1228 const char * ipv6_string_mapped(char *addr_str
, const struct in6_addr
*addr
);
1229 struct in6_addr
ipv6_addr_bitand(const struct in6_addr
*src
,
1230 const struct in6_addr
*mask
);
1231 struct in6_addr
ipv6_addr_bitxor(const struct in6_addr
*a
,
1232 const struct in6_addr
*b
);
1233 bool ipv6_is_zero(const struct in6_addr
*a
);
1234 struct in6_addr
ipv6_create_mask(int mask
);
1235 int ipv6_count_cidr_bits(const struct in6_addr
*netmask
);
1236 bool ipv6_is_cidr(const struct in6_addr
*netmask
);
1238 bool ipv6_parse(const char *s
, struct in6_addr
*ip
);
1239 char *ipv6_parse_masked(const char *s
, struct in6_addr
*ipv6
,
1240 struct in6_addr
*mask
);
1241 char *ipv6_parse_cidr(const char *s
, struct in6_addr
*ip
, unsigned int *plen
)
1242 OVS_WARN_UNUSED_RESULT
;
1243 char *ipv6_parse_masked_len(const char *s
, int *n
, struct in6_addr
*ipv6
,
1244 struct in6_addr
*mask
);
1245 char *ipv6_parse_cidr_len(const char *s
, int *n
, struct in6_addr
*ip
,
1247 OVS_WARN_UNUSED_RESULT
;
1249 void *eth_compose(struct dp_packet
*, const struct eth_addr eth_dst
,
1250 const struct eth_addr eth_src
, uint16_t eth_type
,
1252 void *snap_compose(struct dp_packet
*, const struct eth_addr eth_dst
,
1253 const struct eth_addr eth_src
,
1254 unsigned int oui
, uint16_t snap_type
, size_t size
);
1255 void packet_set_ipv4(struct dp_packet
*, ovs_be32 src
, ovs_be32 dst
, uint8_t tos
,
1257 void packet_set_ipv4_addr(struct dp_packet
*packet
, ovs_16aligned_be32
*addr
,
1259 void packet_set_ipv6(struct dp_packet
*, const struct in6_addr
*src
,
1260 const struct in6_addr
*dst
, uint8_t tc
,
1261 ovs_be32 fl
, uint8_t hlmit
);
1262 void packet_set_ipv6_addr(struct dp_packet
*packet
, uint8_t proto
,
1263 ovs_16aligned_be32 addr
[4],
1264 const struct in6_addr
*new_addr
,
1265 bool recalculate_csum
);
1266 void packet_set_tcp_port(struct dp_packet
*, ovs_be16 src
, ovs_be16 dst
);
1267 void packet_set_udp_port(struct dp_packet
*, ovs_be16 src
, ovs_be16 dst
);
1268 void packet_set_sctp_port(struct dp_packet
*, ovs_be16 src
, ovs_be16 dst
);
1269 void packet_set_icmp(struct dp_packet
*, uint8_t type
, uint8_t code
);
1270 void packet_set_nd(struct dp_packet
*, const struct in6_addr
*target
,
1271 const struct eth_addr sll
, const struct eth_addr tll
);
1273 void packet_format_tcp_flags(struct ds
*, uint16_t);
1274 const char *packet_tcp_flag_to_string(uint32_t flag
);
1275 void compose_arp__(struct dp_packet
*);
1276 void compose_arp(struct dp_packet
*, uint16_t arp_op
,
1277 const struct eth_addr arp_sha
,
1278 const struct eth_addr arp_tha
, bool broadcast
,
1279 ovs_be32 arp_spa
, ovs_be32 arp_tpa
);
1280 void compose_nd_ns(struct dp_packet
*, const struct eth_addr eth_src
,
1281 const struct in6_addr
*ipv6_src
,
1282 const struct in6_addr
*ipv6_dst
);
1283 void compose_nd_na(struct dp_packet
*, const struct eth_addr eth_src
,
1284 const struct eth_addr eth_dst
,
1285 const struct in6_addr
*ipv6_src
,
1286 const struct in6_addr
*ipv6_dst
,
1287 ovs_be32 rso_flags
);
1288 void compose_nd_ra(struct dp_packet
*,
1289 const struct eth_addr eth_src
,
1290 const struct eth_addr eth_dst
,
1291 const struct in6_addr
*ipv6_src
,
1292 const struct in6_addr
*ipv6_dst
,
1293 uint8_t cur_hop_limit
, uint8_t mo_flags
,
1294 ovs_be16 router_lt
, ovs_be32 reachable_time
,
1295 ovs_be32 retrans_timer
, ovs_be32 mtu
);
1296 void packet_put_ra_prefix_opt(struct dp_packet
*,
1297 uint8_t plen
, uint8_t la_flags
,
1298 ovs_be32 valid_lifetime
,
1299 ovs_be32 preferred_lifetime
,
1300 const ovs_be128 router_prefix
);
1301 uint32_t packet_csum_pseudoheader(const struct ip_header
*);
1302 void IP_ECN_set_ce(struct dp_packet
*pkt
, bool is_ipv6
);
1304 #define DNS_HEADER_LEN 12
1307 uint8_t lo_flag
; /* QR (1), OPCODE (4), AA (1), TC (1) and RD (1) */
1308 uint8_t hi_flag
; /* RA (1), Z (3) and RCODE (4) */
1309 ovs_be16 qdcount
; /* Num of entries in the question section. */
1310 ovs_be16 ancount
; /* Num of resource records in the answer section. */
1312 /* Num of name server records in the authority record section. */
1315 /* Num of resource records in the additional records section. */
1319 BUILD_ASSERT_DECL(DNS_HEADER_LEN
== sizeof(struct dns_header
));
1321 #define DNS_QUERY_TYPE_A 0x01
1322 #define DNS_QUERY_TYPE_AAAA 0x1c
1323 #define DNS_QUERY_TYPE_ANY 0xff
1325 #define DNS_CLASS_IN 0x01
1326 #define DNS_DEFAULT_RR_TTL 3600
1328 #endif /* packets.h */