+/* Like struct in6_addr, but whereas that struct requires 32-bit alignment on
+ * most implementations, this one only requires 16-bit alignment. */
+union ovs_16aligned_in6_addr {
+ ovs_be16 be16[8];
+ ovs_16aligned_be32 be32[4];
+};
+
+/* Like struct in6_hdr, but whereas that struct requires 32-bit alignment, this
+ * one only requires 16-bit alignment. */
+struct ovs_16aligned_ip6_hdr {
+ union {
+ struct ovs_16aligned_ip6_hdrctl {
+ ovs_16aligned_be32 ip6_un1_flow;
+ ovs_be16 ip6_un1_plen;
+ uint8_t ip6_un1_nxt;
+ uint8_t ip6_un1_hlim;
+ } ip6_un1;
+ uint8_t ip6_un2_vfc;
+ } ip6_ctlun;
+ union ovs_16aligned_in6_addr ip6_src;
+ union ovs_16aligned_in6_addr ip6_dst;
+};
+
+/* Like struct in6_frag, but whereas that struct requires 32-bit alignment,
+ * this one only requires 16-bit alignment. */
+struct ovs_16aligned_ip6_frag {
+ uint8_t ip6f_nxt;
+ uint8_t ip6f_reserved;
+ ovs_be16 ip6f_offlg;
+ ovs_16aligned_be32 ip6f_ident;
+};
+
+#define ICMP6_HEADER_LEN 4
+struct icmp6_header {
+ uint8_t icmp6_type;
+ uint8_t icmp6_code;
+ ovs_be16 icmp6_cksum;
+};
+BUILD_ASSERT_DECL(ICMP6_HEADER_LEN == sizeof(struct icmp6_header));
+
+/* Neighbor Discovery option field.
+ * ND options are always a multiple of 8 bytes in size. */
+#define ND_OPT_LEN 8
+struct ovs_nd_opt {
+ uint8_t nd_opt_type; /* Values defined in icmp6.h */
+ uint8_t nd_opt_len; /* in units of 8 octets (the size of this struct) */
+ uint8_t nd_opt_data[6]; /* Ethernet address in the case of SLL or TLL options */
+};
+BUILD_ASSERT_DECL(ND_OPT_LEN == sizeof(struct ovs_nd_opt));
+
+/* Like struct nd_msg (from ndisc.h), but whereas that struct requires 32-bit
+ * alignment, this one only requires 16-bit alignment. */
+#define ND_MSG_LEN 24
+struct ovs_nd_msg {
+ struct icmp6_header icmph;
+ ovs_16aligned_be32 rco_flags;
+ union ovs_16aligned_in6_addr target;
+ struct ovs_nd_opt options[0];
+};
+BUILD_ASSERT_DECL(ND_MSG_LEN == sizeof(struct ovs_nd_msg));
+
+/* The IPv6 flow label is in the lower 20 bits of the first 32-bit word. */
+#define IPV6_LABEL_MASK 0x000fffff
+
+/* Example:
+ *
+ * char *string = "1 ::1 2";
+ * char ipv6_s[IPV6_SCAN_LEN + 1];
+ * struct in6_addr ipv6;
+ *
+ * if (ovs_scan(string, "%d"IPV6_SCAN_FMT"%d", &a, ipv6_s, &b)
+ * && inet_pton(AF_INET6, ipv6_s, &ipv6) == 1) {
+ * ...
+ * }
+ */
+#define IPV6_SCAN_FMT "%46[0123456789abcdefABCDEF:.]"
+#define IPV6_SCAN_LEN 46
+
+extern const struct in6_addr in6addr_exact;
+#define IN6ADDR_EXACT_INIT { { { 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, \
+ 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff } } }
+
+static inline bool ipv6_addr_equals(const struct in6_addr *a,
+ const struct in6_addr *b)
+{
+#ifdef IN6_ARE_ADDR_EQUAL
+ return IN6_ARE_ADDR_EQUAL(a, b);
+#else
+ return !memcmp(a, b, sizeof(*a));
+#endif
+}
+
+static inline bool ipv6_mask_is_any(const struct in6_addr *mask) {
+ return ipv6_addr_equals(mask, &in6addr_any);
+}
+
+static inline bool ipv6_mask_is_exact(const struct in6_addr *mask) {
+ return ipv6_addr_equals(mask, &in6addr_exact);
+}
+
+static inline bool dl_type_is_ip_any(ovs_be16 dl_type)
+{
+ return dl_type == htons(ETH_TYPE_IP)
+ || dl_type == htons(ETH_TYPE_IPV6);
+}
+
+/* Tunnel header */
+#define GENEVE_CRIT_OPT_TYPE (1 << 7)
+struct geneve_opt {
+ ovs_be16 opt_class;
+ uint8_t type;
+#ifdef WORDS_BIGENDIAN
+ uint8_t r1:1;
+ uint8_t r2:1;
+ uint8_t r3:1;
+ uint8_t length:5;
+#else
+ uint8_t length:5;
+ uint8_t r3:1;
+ uint8_t r2:1;
+ uint8_t r1:1;
+#endif
+ /* Option data */
+};
+
+struct genevehdr {
+#ifdef WORDS_BIGENDIAN
+ uint8_t ver:2;
+ uint8_t opt_len:6;
+ uint8_t oam:1;
+ uint8_t critical:1;
+ uint8_t rsvd1:6;
+#else
+ uint8_t opt_len:6;
+ uint8_t ver:2;
+ uint8_t rsvd1:6;
+ uint8_t critical:1;
+ uint8_t oam:1;
+#endif
+ ovs_be16 proto_type;
+ ovs_16aligned_be32 vni;
+ struct geneve_opt options[];
+};
+
+/* GRE protocol header */
+struct gre_base_hdr {
+ ovs_be16 flags;
+ ovs_be16 protocol;
+};
+
+#define GRE_CSUM 0x8000
+#define GRE_ROUTING 0x4000
+#define GRE_KEY 0x2000
+#define GRE_SEQ 0x1000
+#define GRE_STRICT 0x0800
+#define GRE_REC 0x0700
+#define GRE_FLAGS 0x00F8
+#define GRE_VERSION 0x0007
+
+/* VXLAN protocol header */
+struct vxlanhdr {
+ ovs_16aligned_be32 vx_flags;
+ ovs_16aligned_be32 vx_vni;
+};
+
+#define VXLAN_FLAGS 0x08000000 /* struct vxlanhdr.vx_flags required value. */
+
+void format_ipv6_addr(char *addr_str, const struct in6_addr *addr);
+void print_ipv6_addr(struct ds *string, const struct in6_addr *addr);
+void print_ipv6_masked(struct ds *string, const struct in6_addr *addr,
+ const struct in6_addr *mask);
+struct in6_addr ipv6_addr_bitand(const struct in6_addr *src,
+ const struct in6_addr *mask);
+struct in6_addr ipv6_create_mask(int mask);
+int ipv6_count_cidr_bits(const struct in6_addr *netmask);
+bool ipv6_is_cidr(const struct in6_addr *netmask);
+
+void *eth_compose(struct dp_packet *, const uint8_t eth_dst[ETH_ADDR_LEN],
+ const uint8_t eth_src[ETH_ADDR_LEN], uint16_t eth_type,
+ size_t size);
+void *snap_compose(struct dp_packet *, const uint8_t eth_dst[ETH_ADDR_LEN],
+ const uint8_t eth_src[ETH_ADDR_LEN],
+ unsigned int oui, uint16_t snap_type, size_t size);
+void packet_set_ipv4(struct dp_packet *, ovs_be32 src, ovs_be32 dst, uint8_t tos,
+ uint8_t ttl);
+void packet_set_ipv6(struct dp_packet *, uint8_t proto, const ovs_be32 src[4],
+ const ovs_be32 dst[4], uint8_t tc,
+ ovs_be32 fl, uint8_t hlmit);
+void packet_set_tcp_port(struct dp_packet *, ovs_be16 src, ovs_be16 dst);
+void packet_set_udp_port(struct dp_packet *, ovs_be16 src, ovs_be16 dst);
+void packet_set_sctp_port(struct dp_packet *, ovs_be16 src, ovs_be16 dst);
+void packet_set_nd(struct dp_packet *, const ovs_be32 target[4],
+ const uint8_t sll[6], const uint8_t tll[6]);
+
+void packet_format_tcp_flags(struct ds *, uint16_t);
+const char *packet_tcp_flag_to_string(uint32_t flag);
+void compose_arp(struct dp_packet *b, const uint8_t eth_src[ETH_ADDR_LEN],
+ ovs_be32 ip_src, ovs_be32 ip_dst);
+uint32_t packet_csum_pseudoheader(const struct ip_header *);
+