/*
- * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Nicira, Inc.
+ * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include <inttypes.h>
#include <sys/types.h>
-#include <netinet/in.h>
#include <stdint.h>
#include <string.h>
#include "compiler.h"
#include "openvswitch/geneve.h"
+#include "openvswitch/packets.h"
#include "openvswitch/types.h"
+#include "openvswitch/nsh.h"
#include "odp-netlink.h"
#include "random.h"
#include "hash.h"
#include "tun-metadata.h"
#include "unaligned.h"
#include "util.h"
+#include "timeval.h"
struct dp_packet;
+struct conn;
struct ds;
-/* Tunnel information used in flow key and metadata. */
-struct flow_tnl {
- ovs_be32 ip_dst;
- struct in6_addr ipv6_dst;
- ovs_be32 ip_src;
- struct in6_addr ipv6_src;
- ovs_be64 tun_id;
- uint16_t flags;
- uint8_t ip_tos;
- uint8_t ip_ttl;
- ovs_be16 tp_src;
- ovs_be16 tp_dst;
- ovs_be16 gbp_id;
- uint8_t gbp_flags;
- uint8_t pad1[5]; /* Pad to 64 bits. */
- struct tun_metadata metadata;
-};
-
-/* Some flags are exposed through OpenFlow while others are used only
- * internally. */
-
-/* Public flags */
-#define FLOW_TNL_F_OAM (1 << 0)
-
-#define FLOW_TNL_PUB_F_MASK ((1 << 1) - 1)
-
-/* Private flags */
-#define FLOW_TNL_F_DONT_FRAGMENT (1 << 1)
-#define FLOW_TNL_F_CSUM (1 << 2)
-#define FLOW_TNL_F_KEY (1 << 3)
-
-#define FLOW_TNL_F_MASK ((1 << 4) - 1)
-
/* Purely internal to OVS userspace. These flags should never be exposed to
* the outside world and so aren't included in the flags mask. */
return tnl->ip_dst || ipv6_addr_is_set(&tnl->ipv6_dst);
}
+static inline bool
+flow_tnl_src_is_set(const struct flow_tnl *tnl)
+{
+ return tnl->ip_src || ipv6_addr_is_set(&tnl->ipv6_src);
+}
+
struct in6_addr flow_tnl_dst(const struct flow_tnl *tnl);
struct in6_addr flow_tnl_src(const struct flow_tnl *tnl);
return a_size == flow_tnl_size(b) && !memcmp(a, b, a_size);
}
-/* Unfortunately, a "struct flow" sometimes has to handle OpenFlow port
- * numbers and other times datapath (dpif) port numbers. This union allows
- * access to both. */
-union flow_in_port {
- odp_port_t odp_port;
- ofp_port_t ofp_port;
-};
-
/* Datapath packet metadata */
struct pkt_metadata {
+PADDED_MEMBERS_CACHELINE_MARKER(CACHE_LINE_SIZE, cacheline0,
uint32_t recirc_id; /* Recirculation id carried with the
recirculating packets. 0 for packets
received from the wire. */
action. */
uint32_t skb_priority; /* Packet priority for QoS. */
uint32_t pkt_mark; /* Packet mark. */
- uint16_t ct_state; /* Connection state. */
+ uint8_t ct_state; /* Connection state. */
+ bool ct_orig_tuple_ipv6;
uint16_t ct_zone; /* Connection zone. */
uint32_t ct_mark; /* Connection mark. */
ovs_u128 ct_label; /* Connection label. */
union flow_in_port in_port; /* Input port. */
+ struct conn *conn; /* Cached conntrack connection. */
+ bool reply; /* True if reply direction. */
+ bool icmp_related; /* True if ICMP related. */
+);
+
+PADDED_MEMBERS_CACHELINE_MARKER(CACHE_LINE_SIZE, cacheline1,
+ union { /* Populated only for non-zero 'ct_state'. */
+ struct ovs_key_ct_tuple_ipv4 ipv4;
+ struct ovs_key_ct_tuple_ipv6 ipv6; /* Used only if */
+ } ct_orig_tuple; /* 'ct_orig_tuple_ipv6' is set */
+);
+
+PADDED_MEMBERS_CACHELINE_MARKER(CACHE_LINE_SIZE, cacheline2,
struct flow_tnl tunnel; /* Encapsulating tunnel parameters. Note that
* if 'ip_dst' == 0, the rest of the fields may
* be uninitialized. */
+);
};
+BUILD_ASSERT_DECL(offsetof(struct pkt_metadata, cacheline0) == 0);
+BUILD_ASSERT_DECL(offsetof(struct pkt_metadata, cacheline1) ==
+ CACHE_LINE_SIZE);
+BUILD_ASSERT_DECL(offsetof(struct pkt_metadata, cacheline2) ==
+ 2 * CACHE_LINE_SIZE);
+
+static inline void
+pkt_metadata_init_tnl(struct pkt_metadata *md)
+{
+ /* Zero up through the tunnel metadata options. The length and table
+ * are before this and as long as they are empty, the options won't
+ * be looked at. */
+ memset(md, 0, offsetof(struct pkt_metadata, tunnel.metadata.opts));
+}
+
+static inline void
+pkt_metadata_init_conn(struct pkt_metadata *md)
+{
+ md->conn = NULL;
+}
+
static inline void
pkt_metadata_init(struct pkt_metadata *md, odp_port_t port)
{
+ /* This is called for every packet in userspace datapath and affects
+ * performance if all the metadata is initialized. Hence, fields should
+ * only be zeroed out when necessary.
+ *
+ * Initialize only till ct_state. Once the ct_state is zeroed out rest
+ * of ct fields will not be looked at unless ct_state != 0.
+ */
+ memset(md, 0, offsetof(struct pkt_metadata, ct_orig_tuple_ipv6));
+
/* It can be expensive to zero out all of the tunnel metadata. However,
* we can just zero out ip_dst and the rest of the data will never be
* looked at. */
- memset(md, 0, offsetof(struct pkt_metadata, in_port));
md->tunnel.ip_dst = 0;
md->tunnel.ipv6_dst = in6addr_any;
-
md->in_port.odp_port = port;
+ md->conn = NULL;
}
/* This function prefetches the cachelines touched by pkt_metadata_init()
- * For performance reasons the two functions should be kept in sync. */
+ * and pkt_metadata_init_tnl(). For performance reasons the two functions
+ * should be kept in sync. */
static inline void
pkt_metadata_prefetch_init(struct pkt_metadata *md)
{
- ovs_prefetch_range(md, offsetof(struct pkt_metadata, tunnel.ip_src));
+ /* Prefetch cacheline0 as members till ct_state and odp_port will
+ * be initialized later in pkt_metadata_init(). */
+ OVS_PREFETCH(md->cacheline0);
+
+ /* Prefetch cacheline1 as members of this cacheline will be zeroed out
+ * in pkt_metadata_init_tnl(). */
+ OVS_PREFETCH(md->cacheline1);
+
+ /* Prefetch cachline2 as ip_dst & ipv6_dst fields will be initialized. */
+ OVS_PREFETCH(md->cacheline2);
}
bool dpid_from_string(const char *s, uint64_t *dpidp);
#define ETH_ADDR_LEN 6
static const struct eth_addr eth_addr_broadcast OVS_UNUSED
- = { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } } };
+ = ETH_ADDR_C(ff,ff,ff,ff,ff,ff);
static const struct eth_addr eth_addr_exact OVS_UNUSED
- = { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } } };
+ = ETH_ADDR_C(ff,ff,ff,ff,ff,ff);
static const struct eth_addr eth_addr_zero OVS_UNUSED
- = { { { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } };
+ = ETH_ADDR_C(00,00,00,00,00,00);
+static const struct eth_addr64 eth_addr64_zero OVS_UNUSED
+ = ETH_ADDR64_C(00,00,00,00,00,00,00,00);
static const struct eth_addr eth_addr_stp OVS_UNUSED
- = { { { 0x01, 0x80, 0xC2, 0x00, 0x00, 0x00 } } };
+ = ETH_ADDR_C(01,80,c2,00,00,00);
static const struct eth_addr eth_addr_lacp OVS_UNUSED
- = { { { 0x01, 0x80, 0xC2, 0x00, 0x00, 0x02 } } };
+ = ETH_ADDR_C(01,80,c2,00,00,02);
static const struct eth_addr eth_addr_bfd OVS_UNUSED
- = { { { 0x00, 0x23, 0x20, 0x00, 0x00, 0x01 } } };
+ = ETH_ADDR_C(00,23,20,00,00,01);
static inline bool eth_addr_is_broadcast(const struct eth_addr a)
{
{
return !(a.be16[0] | a.be16[1] | a.be16[2]);
}
+static inline bool eth_addr64_is_zero(const struct eth_addr64 a)
+{
+ return !(a.be16[0] | a.be16[1] | a.be16[2] | a.be16[3]);
+}
static inline int eth_mask_is_exact(const struct eth_addr a)
{
{
return memcmp(&a, &b, sizeof a);
}
+static inline int eth_addr64_compare_3way(const struct eth_addr64 a,
+ const struct eth_addr64 b)
+{
+ return memcmp(&a, &b, sizeof a);
+}
static inline bool eth_addr_equals(const struct eth_addr a,
const struct eth_addr b)
{
return !eth_addr_compare_3way(a, b);
}
+static inline bool eth_addr64_equals(const struct eth_addr64 a,
+ const struct eth_addr64 b)
+{
+ return !eth_addr64_compare_3way(a, b);
+}
static inline bool eth_addr_equal_except(const struct eth_addr a,
const struct eth_addr b,
|| ((a.be16[2] ^ b.be16[2]) & mask.be16[2]));
}
-static inline uint64_t eth_addr_to_uint64(const struct eth_addr ea)
-{
- return (((uint64_t) ntohs(ea.be16[0]) << 32)
- | ((uint64_t) ntohs(ea.be16[1]) << 16)
- | ntohs(ea.be16[2]));
-}
+uint64_t eth_addr_to_uint64(const struct eth_addr ea);
static inline uint64_t eth_addr_vlan_to_uint64(const struct eth_addr ea,
uint16_t vlan)
return (((uint64_t)vlan << 48) | eth_addr_to_uint64(ea));
}
-static inline void eth_addr_from_uint64(uint64_t x, struct eth_addr *ea)
-{
- ea->be16[0] = htons(x >> 32);
- ea->be16[1] = htons((x & 0xFFFF0000) >> 16);
- ea->be16[2] = htons(x & 0xFFFF);
-}
+void eth_addr_from_uint64(uint64_t x, struct eth_addr *ea);
static inline struct eth_addr eth_addr_invert(const struct eth_addr src)
{
return dst;
}
-static inline void eth_addr_mark_random(struct eth_addr *ea)
-{
- ea->ea[0] &= ~1; /* Unicast. */
- ea->ea[0] |= 2; /* Private. */
-}
+void eth_addr_mark_random(struct eth_addr *ea);
static inline void eth_addr_random(struct eth_addr *ea)
{
(EAB)[0], (EAB)[1], (EAB)[2], (EAB)[3], (EAB)[4], (EAB)[5]
#define ETH_ADDR_STRLEN 17
+/* Example:
+ *
+ * struct eth_addr64 eui64;
+ * [...]
+ * printf("The EUI-64 address is "ETH_ADDR64_FMT"\n", ETH_ADDR64_ARGS(mac));
+ *
+ */
+#define ETH_ADDR64_FMT \
+ "%02"PRIx8":%02"PRIx8":%02"PRIx8":%02"PRIx8":" \
+ "%02"PRIx8":%02"PRIx8":%02"PRIx8":%02"PRIx8
+#define ETH_ADDR64_ARGS(EA) ETH_ADDR64_BYTES_ARGS((EA).ea64)
+#define ETH_ADDR64_BYTES_ARGS(EAB) \
+ (EAB)[0], (EAB)[1], (EAB)[2], (EAB)[3], \
+ (EAB)[4], (EAB)[5], (EAB)[6], (EAB)[7]
+#define ETH_ADDR64_STRLEN 23
+
/* Example:
*
* char *string = "1 00:11:22:33:44:55 2";
#define ETH_TYPE_RARP 0x8035
#define ETH_TYPE_MPLS 0x8847
#define ETH_TYPE_MPLS_MCAST 0x8848
+#define ETH_TYPE_NSH 0x894f
+#define ETH_TYPE_ERSPAN1 0x88be /* version 1 type II */
+#define ETH_TYPE_ERSPAN2 0x22eb /* version 2 type III */
static inline bool eth_type_mpls(ovs_be16 eth_type)
{
#define ETH_TOTAL_MIN (ETH_HEADER_LEN + ETH_PAYLOAD_MIN)
#define ETH_TOTAL_MAX (ETH_HEADER_LEN + ETH_PAYLOAD_MAX)
#define ETH_VLAN_TOTAL_MAX (ETH_HEADER_LEN + VLAN_HEADER_LEN + ETH_PAYLOAD_MAX)
-OVS_PACKED(
struct eth_header {
struct eth_addr eth_dst;
struct eth_addr eth_src;
ovs_be16 eth_type;
-});
+};
BUILD_ASSERT_DECL(ETH_HEADER_LEN == sizeof(struct eth_header));
+void push_eth(struct dp_packet *packet, const struct eth_addr *dst,
+ const struct eth_addr *src);
+void pop_eth(struct dp_packet *packet);
+
+void push_nsh(struct dp_packet *packet, const struct nsh_hdr *nsh_hdr_src);
+bool pop_nsh(struct dp_packet *packet);
+
#define LLC_DSAP_SNAP 0xaa
#define LLC_SSAP_SNAP 0xaa
#define LLC_CNTL_SNAP 3
#define LLC_HEADER_LEN 3
-OVS_PACKED(
struct llc_header {
uint8_t llc_dsap;
uint8_t llc_ssap;
uint8_t llc_cntl;
-});
+};
BUILD_ASSERT_DECL(LLC_HEADER_LEN == sizeof(struct llc_header));
/* LLC field values used for STP frames. */
BUILD_ASSERT_DECL(VLAN_HEADER_LEN == sizeof(struct vlan_header));
#define VLAN_ETH_HEADER_LEN (ETH_HEADER_LEN + VLAN_HEADER_LEN)
-OVS_PACKED(
struct vlan_eth_header {
struct eth_addr veth_dst;
struct eth_addr veth_src;
ovs_be16 veth_type; /* Always htons(ETH_TYPE_VLAN). */
ovs_be16 veth_tci; /* Lowest 12 bits are VLAN ID. */
ovs_be16 veth_next_type;
-});
+};
BUILD_ASSERT_DECL(VLAN_ETH_HEADER_LEN == sizeof(struct vlan_eth_header));
/* MPLS related definitions */
return (ntohl(mpls_lse) & MPLS_TTL_MASK) >> MPLS_TTL_SHIFT;
}
+/* Set label in mpls lse. */
+static inline void
+flow_set_mpls_lse_label(ovs_be32 *mpls_lse, uint32_t label)
+{
+ *mpls_lse &= ~htonl(MPLS_LABEL_MASK);
+ *mpls_lse |= htonl(label << MPLS_LABEL_SHIFT);
+}
+
+/* Set TC in mpls lse. */
+static inline void
+flow_set_mpls_lse_tc(ovs_be32 *mpls_lse, uint8_t tc)
+{
+ *mpls_lse &= ~htonl(MPLS_TC_MASK);
+ *mpls_lse |= htonl((tc & 0x7) << MPLS_TC_SHIFT);
+}
+
+/* Set BOS in mpls lse. */
+static inline void
+flow_set_mpls_lse_bos(ovs_be32 *mpls_lse, uint8_t bos)
+{
+ *mpls_lse &= ~htonl(MPLS_BOS_MASK);
+ *mpls_lse |= htonl((bos & 0x1) << MPLS_BOS_SHIFT);
+}
+
/* Set TTL in mpls lse. */
static inline void
flow_set_mpls_lse_ttl(ovs_be32 *mpls_lse, uint8_t ttl)
&((uint8_t *) ip)[2], \
&((uint8_t *) ip)[3]
+#define IP_PORT_SCAN_FMT "%"SCNu8".%"SCNu8".%"SCNu8".%"SCNu8":%"SCNu16
+#define IP_PORT_SCAN_ARGS(ip, port) \
+ ((void) (ovs_be32) *(ip), &((uint8_t *) ip)[0]), \
+ &((uint8_t *) ip)[1], \
+ &((uint8_t *) ip)[2], \
+ &((uint8_t *) ip)[3], \
+ ((void) (ovs_be16) *(port), (uint16_t *) port)
+
/* Returns true if 'netmask' is a CIDR netmask, that is, if it consists of N
* high-order 1-bits and 32-N low-order 0-bits. */
static inline bool
int ip_count_cidr_bits(ovs_be32 netmask);
void ip_format_masked(ovs_be32 ip, ovs_be32 mask, struct ds *);
bool ip_parse(const char *s, ovs_be32 *ip);
+char *ip_parse_port(const char *s, ovs_be32 *ip, ovs_be16 *port)
+ OVS_WARN_UNUSED_RESULT;
char *ip_parse_masked(const char *s, ovs_be32 *ip, ovs_be32 *mask)
OVS_WARN_UNUSED_RESULT;
char *ip_parse_cidr(const char *s, ovs_be32 *ip, unsigned int *plen)
#define IPPROTO_SCTP 132
#endif
+#ifndef IPPROTO_DCCP
+#define IPPROTO_DCCP 33
+#endif
+
+#ifndef IPPROTO_IGMP
+#define IPPROTO_IGMP 2
+#endif
+
+#ifndef IPPROTO_UDPLITE
+#define IPPROTO_UDPLITE 136
+#endif
+
/* TOS fields. */
#define IP_ECN_NOT_ECT 0x0
#define IP_ECN_ECT_1 0x01
#define IP_ECN_ECT_0 0x02
#define IP_ECN_CE 0x03
#define IP_ECN_MASK 0x03
+#define IP_DSCP_CS6 0xc0
#define IP_DSCP_MASK 0xfc
+static inline int
+IP_ECN_is_ce(uint8_t dsfield)
+{
+ return (dsfield & IP_ECN_MASK) == IP_ECN_CE;
+}
+
#define IP_VERSION 4
#define IP_DONT_FRAGMENT 0x4000 /* Don't fragment. */
ovs_16aligned_be32 ip_src;
ovs_16aligned_be32 ip_dst;
};
-
BUILD_ASSERT_DECL(IP_HEADER_LEN == sizeof(struct ip_header));
+/* ICMPv4 types. */
+#define ICMP4_ECHO_REPLY 0
+#define ICMP4_DST_UNREACH 3
+#define ICMP4_SOURCEQUENCH 4
+#define ICMP4_REDIRECT 5
+#define ICMP4_ECHO_REQUEST 8
+#define ICMP4_TIME_EXCEEDED 11
+#define ICMP4_PARAM_PROB 12
+#define ICMP4_TIMESTAMP 13
+#define ICMP4_TIMESTAMPREPLY 14
+#define ICMP4_INFOREQUEST 15
+#define ICMP4_INFOREPLY 16
+
#define ICMP_HEADER_LEN 8
struct icmp_header {
uint8_t icmp_type;
};
BUILD_ASSERT_DECL(ICMP_HEADER_LEN == sizeof(struct icmp_header));
+/* ICMPV4 */
+#define ICMP_ERROR_DATA_L4_LEN 8
+
#define IGMP_HEADER_LEN 8
struct igmp_header {
uint8_t igmp_type;
};
BUILD_ASSERT_DECL(IGMPV3_HEADER_LEN == sizeof(struct igmpv3_header));
+#define IGMPV3_QUERY_HEADER_LEN 12
+struct igmpv3_query_header {
+ uint8_t type;
+ uint8_t max_resp;
+ ovs_be16 csum;
+ ovs_16aligned_be32 group;
+ uint8_t srs_qrv;
+ uint8_t qqic;
+ ovs_be16 nsrcs;
+};
+BUILD_ASSERT_DECL(
+ IGMPV3_QUERY_HEADER_LEN == sizeof(struct igmpv3_query_header
+));
+
#define IGMPV3_RECORD_LEN 8
struct igmpv3_record {
uint8_t type;
};
BUILD_ASSERT_DECL(UDP_HEADER_LEN == sizeof(struct udp_header));
+#define ESP_HEADER_LEN 8
+struct esp_header {
+ ovs_be32 spi;
+ ovs_be32 seq_no;
+};
+BUILD_ASSERT_DECL(ESP_HEADER_LEN == sizeof(struct esp_header));
+
+#define ESP_TRAILER_LEN 2
+struct esp_trailer {
+ uint8_t pad_len;
+ uint8_t next_hdr;
+};
+BUILD_ASSERT_DECL(ESP_TRAILER_LEN == sizeof(struct esp_trailer));
+
#define TCP_FIN 0x001
#define TCP_SYN 0x002
#define TCP_RST 0x004
};
BUILD_ASSERT_DECL(TCP_HEADER_LEN == sizeof(struct tcp_header));
-/* Connection states */
-enum {
- CS_NEW_BIT = 0,
- CS_ESTABLISHED_BIT = 1,
- CS_RELATED_BIT = 2,
- CS_REPLY_DIR_BIT = 3,
- CS_INVALID_BIT = 4,
- CS_TRACKED_BIT = 5,
- CS_SRC_NAT_BIT = 6,
- CS_DST_NAT_BIT = 7,
-};
+/* Connection states.
+ *
+ * Names like CS_RELATED are bit values, e.g. 1 << 2.
+ * Names like CS_RELATED_BIT are bit indexes, e.g. 2. */
+#define CS_STATES \
+ CS_STATE(NEW, 0, "new") \
+ CS_STATE(ESTABLISHED, 1, "est") \
+ CS_STATE(RELATED, 2, "rel") \
+ CS_STATE(REPLY_DIR, 3, "rpl") \
+ CS_STATE(INVALID, 4, "inv") \
+ CS_STATE(TRACKED, 5, "trk") \
+ CS_STATE(SRC_NAT, 6, "snat") \
+ CS_STATE(DST_NAT, 7, "dnat")
enum {
- CS_NEW = (1 << CS_NEW_BIT),
- CS_ESTABLISHED = (1 << CS_ESTABLISHED_BIT),
- CS_RELATED = (1 << CS_RELATED_BIT),
- CS_REPLY_DIR = (1 << CS_REPLY_DIR_BIT),
- CS_INVALID = (1 << CS_INVALID_BIT),
- CS_TRACKED = (1 << CS_TRACKED_BIT),
- CS_SRC_NAT = (1 << CS_SRC_NAT_BIT),
- CS_DST_NAT = (1 << CS_DST_NAT_BIT),
+#define CS_STATE(ENUM, INDEX, NAME) \
+ CS_##ENUM = 1 << INDEX, \
+ CS_##ENUM##_BIT = INDEX,
+ CS_STATES
+#undef CS_STATE
};
/* Undefined connection state bits. */
-#define CS_SUPPORTED_MASK (CS_NEW | CS_ESTABLISHED | CS_RELATED \
- | CS_INVALID | CS_REPLY_DIR | CS_TRACKED \
- | CS_SRC_NAT | CS_DST_NAT)
+enum {
+#define CS_STATE(ENUM, INDEX, NAME) +CS_##ENUM
+ CS_SUPPORTED_MASK = CS_STATES
+#undef CS_STATE
+};
#define CS_UNSUPPORTED_MASK (~(uint32_t)CS_SUPPORTED_MASK)
#define ARP_HRD_ETHERNET 1
ovs_16aligned_be32 be32[4];
};
-/* Like struct in6_hdr, but whereas that struct requires 32-bit alignment, this
+/* Like struct ip6_hdr, but whereas that struct requires 32-bit alignment, this
* one only requires 16-bit alignment. */
struct ovs_16aligned_ip6_hdr {
union {
};
BUILD_ASSERT_DECL(ICMP6_HEADER_LEN == sizeof(struct icmp6_header));
+#define ICMP6_DATA_HEADER_LEN 8
+struct icmp6_data_header {
+ struct icmp6_header icmp6_base;
+ union {
+ ovs_16aligned_be32 be32[1];
+ ovs_be16 be16[2];
+ uint8_t u8[4];
+ } icmp6_data;
+};
+BUILD_ASSERT_DECL(ICMP6_DATA_HEADER_LEN == sizeof(struct icmp6_data_header));
+
uint32_t packet_csum_pseudoheader6(const struct ovs_16aligned_ip6_hdr *);
+ovs_be16 packet_csum_upperlayer6(const struct ovs_16aligned_ip6_hdr *,
+ const void *, uint8_t, uint16_t);
/* 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) */
- struct eth_addr nd_opt_mac; /* Ethernet address in the case of SLL or TLL options */
+#define ND_LLA_OPT_LEN 8
+struct ovs_nd_lla_opt {
+ uint8_t type; /* One of ND_OPT_*_LINKADDR. */
+ uint8_t len;
+ struct eth_addr mac;
+};
+BUILD_ASSERT_DECL(ND_LLA_OPT_LEN == sizeof(struct ovs_nd_lla_opt));
+
+/* Neighbor Discovery option: Prefix Information. */
+#define ND_PREFIX_OPT_LEN 32
+struct ovs_nd_prefix_opt {
+ uint8_t type; /* ND_OPT_PREFIX_INFORMATION. */
+ uint8_t len; /* Always 4. */
+ uint8_t prefix_len;
+ uint8_t la_flags; /* ND_PREFIX_* flags. */
+ ovs_16aligned_be32 valid_lifetime;
+ ovs_16aligned_be32 preferred_lifetime;
+ ovs_16aligned_be32 reserved; /* Always 0. */
+ union ovs_16aligned_in6_addr prefix;
};
-BUILD_ASSERT_DECL(ND_OPT_LEN == sizeof(struct ovs_nd_opt));
+BUILD_ASSERT_DECL(ND_PREFIX_OPT_LEN == sizeof(struct ovs_nd_prefix_opt));
+
+/* Neighbor Discovery option: MTU. */
+#define ND_MTU_OPT_LEN 8
+#define ND_MTU_DEFAULT 0
+struct ovs_nd_mtu_opt {
+ uint8_t type; /* ND_OPT_MTU */
+ uint8_t len; /* Always 1. */
+ ovs_be16 reserved; /* Always 0. */
+ ovs_16aligned_be32 mtu;
+};
+BUILD_ASSERT_DECL(ND_MTU_OPT_LEN == sizeof(struct ovs_nd_mtu_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;
+ ovs_16aligned_be32 rso_flags;
union ovs_16aligned_in6_addr target;
- struct ovs_nd_opt options[0];
+ struct ovs_nd_lla_opt options[0];
};
BUILD_ASSERT_DECL(ND_MSG_LEN == sizeof(struct ovs_nd_msg));
+/* Neighbor Discovery packet flags. */
+#define ND_RSO_ROUTER 0x80000000
+#define ND_RSO_SOLICITED 0x40000000
+#define ND_RSO_OVERRIDE 0x20000000
+
+#define RA_MSG_LEN 16
+struct ovs_ra_msg {
+ struct icmp6_header icmph;
+ uint8_t cur_hop_limit;
+ uint8_t mo_flags; /* ND_RA_MANAGED_ADDRESS and ND_RA_OTHER_CONFIG flags. */
+ ovs_be16 router_lifetime;
+ ovs_be32 reachable_time;
+ ovs_be32 retrans_timer;
+ struct ovs_nd_lla_opt options[0];
+};
+BUILD_ASSERT_DECL(RA_MSG_LEN == sizeof(struct ovs_ra_msg));
+
+#define ND_RA_MANAGED_ADDRESS 0x80
+#define ND_RA_OTHER_CONFIG 0x40
+
+/* Defaults based on MaxRtrInterval and MinRtrInterval from RFC 4861 section
+ * 6.2.1
+ */
+#define ND_RA_MAX_INTERVAL_DEFAULT 600
+
+static inline int
+nd_ra_min_interval_default(int max)
+{
+ return max >= 9 ? max / 3 : max * 3 / 4;
+}
+
/*
* Use the same struct for MLD and MLD2, naming members as the defined fields in
* in the corresponding version of the protocol, though they are reserved in the
#define IN6ADDR_ALL_HOSTS_INIT { { { 0xff,0x02,0x00,0x00,0x00,0x00,0x00,0x00, \
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01 } } }
+extern const struct in6_addr in6addr_all_routers;
+#define IN6ADDR_ALL_ROUTERS_INIT { { { 0xff,0x02,0x00,0x00,0x00,0x00,0x00,0x00, \
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02 } } }
+
static inline bool ipv6_addr_equals(const struct in6_addr *a,
const struct in6_addr *b)
{
#endif
}
+/* Checks the IPv6 address in 'mask' for all zeroes. */
static inline bool ipv6_mask_is_any(const struct in6_addr *mask) {
return ipv6_addr_equals(mask, &in6addr_any);
}
static inline struct in6_addr
in6_addr_mapped_ipv4(ovs_be32 ip4)
{
- struct in6_addr ip6 = { .s6_addr = { [10] = 0xff, [11] = 0xff } };
+ struct in6_addr ip6;
+ memset(&ip6, 0, sizeof(ip6));
+ ip6.s6_addr[10] = 0xff, ip6.s6_addr[11] = 0xff;
memcpy(&ip6.s6_addr[12], &ip4, 4);
return ip6;
}
static inline ovs_be32
in6_addr_get_mapped_ipv4(const struct in6_addr *addr)
{
- union ovs_16aligned_in6_addr *taddr = (void *) addr;
+ union ovs_16aligned_in6_addr *taddr =
+ (union ovs_16aligned_in6_addr *) addr;
if (IN6_IS_ADDR_V4MAPPED(addr)) {
return get_16aligned_be32(&taddr->be32[3]);
} else {
}
}
-static inline void
-in6_addr_solicited_node(struct in6_addr *addr, const struct in6_addr *ip6)
-{
- union ovs_16aligned_in6_addr *taddr = (void *) addr;
- memset(taddr->be16, 0, sizeof(taddr->be16));
- taddr->be16[0] = htons(0xff02);
- taddr->be16[5] = htons(0x1);
- taddr->be16[6] = htons(0xff00);
- memcpy(&addr->s6_addr[13], &ip6->s6_addr[13], 3);
-}
+void in6_addr_solicited_node(struct in6_addr *addr,
+ const struct in6_addr *ip6);
-/*
- * Generates ipv6 link local address from the given eth addr
- * with prefix 'fe80::/64' and stores it in 'lla'
- */
-static inline void
-in6_generate_lla(struct eth_addr ea, struct in6_addr *lla)
-{
- union ovs_16aligned_in6_addr *taddr = (void *) lla;
- memset(taddr->be16, 0, sizeof(taddr->be16));
- taddr->be16[0] = htons(0xfe80);
- taddr->be16[4] = htons(((ea.ea[0] ^ 0x02) << 8) | ea.ea[1]);
- taddr->be16[5] = htons(ea.ea[2] << 8 | 0x00ff);
- taddr->be16[6] = htons(0xfe << 8 | ea.ea[3]);
- taddr->be16[7] = ea.be16[2];
-}
+void in6_generate_eui64(struct eth_addr ea, const struct in6_addr *prefix,
+ struct in6_addr *lla);
-static inline void
-ipv6_multicast_to_ethernet(struct eth_addr *eth, const struct in6_addr *ip6)
-{
- eth->ea[0] = 0x33;
- eth->ea[1] = 0x33;
- eth->ea[2] = ip6->s6_addr[12];
- eth->ea[3] = ip6->s6_addr[13];
- eth->ea[4] = ip6->s6_addr[14];
- eth->ea[5] = ip6->s6_addr[15];
-}
+void in6_generate_lla(struct eth_addr ea, struct in6_addr *lla);
+
+/* Returns true if 'addr' is a link local address. Otherwise, false. */
+bool in6_is_lla(struct in6_addr *addr);
+
+void ipv6_multicast_to_ethernet(struct eth_addr *eth,
+ const struct in6_addr *ip6);
static inline bool dl_type_is_ip_any(ovs_be16 dl_type)
{
#define GRE_FLAGS 0x00F8
#define GRE_VERSION 0x0007
+/*
+ * ERSPAN protocol header and metadata
+ *
+ * Version 1 (Type II) header (8 octets [42:49])
+ * 0 1 2 3
+ * 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
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * | Ver | VLAN | COS | En|T| Session ID |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * | Reserved | Index |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ *
+ *
+ * ERSPAN Version 2 (Type III) header (12 octets [42:49])
+ * 0 1 2 3
+ * 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
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * | Ver | VLAN | COS |BSO|T| Session ID |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * | Timestamp |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * | SGT |P| FT | Hw ID |D|Gra|O|
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ *
+ */
+
+/* ERSPAN has fixed 8-byte GRE header */
+#define ERSPAN_GREHDR_LEN 8
+#define ERSPAN_HDR(gre_base_hdr) \
+ ((struct erspan_base_hdr *)((char *)gre_base_hdr + ERSPAN_GREHDR_LEN))
+
+#define ERSPAN_V1_MDSIZE 4
+#define ERSPAN_V2_MDSIZE 8
+
+#define ERSPAN_SID_MASK 0x03ff /* 10-bit Session ID. */
+#define ERSPAN_IDX_MASK 0xfffff /* v1 Index */
+#define ERSPAN_HWID_MASK 0x03f0
+#define ERSPAN_DIR_MASK 0x0008
+
+struct erspan_base_hdr {
+#ifdef WORDS_BIGENDIAN
+ uint8_t ver:4,
+ vlan_upper:4;
+ uint8_t vlan:8;
+ uint8_t cos:3,
+ en:2,
+ t:1,
+ session_id_upper:2;
+ uint8_t session_id:8;
+#else
+ uint8_t vlan_upper:4,
+ ver:4;
+ uint8_t vlan:8;
+ uint8_t session_id_upper:2,
+ t:1,
+ en:2,
+ cos:3;
+ uint8_t session_id:8;
+#endif
+};
+
+struct erspan_md2 {
+ ovs_16aligned_be32 timestamp;
+ ovs_be16 sgt;
+#ifdef WORDS_BIGENDIAN
+ uint8_t p:1,
+ ft:5,
+ hwid_upper:2;
+ uint8_t hwid:4,
+ dir:1,
+ gra:2,
+ o:1;
+#else
+ uint8_t hwid_upper:2,
+ ft:5,
+ p:1;
+ uint8_t o:1,
+ gra:2,
+ dir:1,
+ hwid:4;
+#endif
+};
+
+struct erspan_metadata {
+ int version;
+ union {
+ ovs_be32 index; /* Version 1 (type II)*/
+ struct erspan_md2 md2; /* Version 2 (type III) */
+ } u;
+};
+
+static inline uint16_t get_sid(const struct erspan_base_hdr *ershdr)
+{
+ return (ershdr->session_id_upper << 8) + ershdr->session_id;
+}
+
+static inline void set_sid(struct erspan_base_hdr *ershdr, uint16_t id)
+{
+ ershdr->session_id = id & 0xff;
+ ershdr->session_id_upper = (id >> 8) &0x3;
+}
+
+static inline uint8_t get_hwid(const struct erspan_md2 *md2)
+{
+ return (md2->hwid_upper << 4) + md2->hwid;
+}
+
+static inline void set_hwid(struct erspan_md2 *md2, uint8_t hwid)
+{
+ md2->hwid = hwid & 0xf;
+ md2->hwid_upper = (hwid >> 4) & 0x3;
+}
+
+/* ERSPAN timestamp granularity
+ * 00b --> granularity = 100 microseconds
+ * 01b --> granularity = 100 nanoseconds
+ * 10b --> granularity = IEEE 1588
+ * Here we only support 100 microseconds.
+ */
+enum erspan_ts_gra {
+ ERSPAN_100US,
+ ERSPAN_100NS,
+ ERSPAN_IEEE1588,
+};
+
+static inline ovs_be32 get_erspan_ts(enum erspan_ts_gra gra)
+{
+ ovs_be32 ts = 0;
+
+ switch (gra) {
+ case ERSPAN_100US:
+ ts = htonl((uint32_t)(time_wall_usec() / 100));
+ break;
+ case ERSPAN_100NS:
+ /* fall back */
+ case ERSPAN_IEEE1588:
+ /* fall back */
+ default:
+ OVS_NOT_REACHED();
+ break;
+ }
+ return ts;
+}
+
+/*
+ * GTP-U protocol header and metadata
+ * See:
+ * User Plane Protocol and Architectural Analysis on 3GPP 5G System
+ * draft-hmm-dmm-5g-uplane-analysis-00
+ *
+ * 0 1 2 3
+ * 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
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * | Ver |P|R|E|S|N| Message Type| Length |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * | Tunnel Endpoint Identifier |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * | Sequence Number | N-PDU Number | Next-Ext-Hdr |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ *
+ * GTP-U Flags:
+ * P: Protocol Type (Set to '1')
+ * R: Reserved Bit (Set to '0')
+ * E: Extension Header Flag (Set to '1' if extension header exists)
+ * S: Sequence Number Flag (Set to '1' if sequence number exists)
+ * N: N-PDU Number Flag (Set to '1' if N-PDU number exists)
+ *
+ * GTP-U Message Type:
+ * Indicates the type of GTP-U message.
+ *
+ * GTP-U Length:
+ * Indicates the length in octets of the payload.
+ *
+ * User payload is transmitted in G-PDU packets.
+ */
+
+#define GTPU_VER_MASK 0xe0
+#define GTPU_P_MASK 0x10
+#define GTPU_E_MASK 0x04
+#define GTPU_S_MASK 0x02
+
+/* GTP-U UDP port. */
+#define GTPU_DST_PORT 2152
+
+/* Default GTP-U flags: Ver = 1 and P = 1. */
+#define GTPU_FLAGS_DEFAULT 0x30
+
+/* GTP-U message type for normal user plane PDU. */
+#define GTPU_MSGTYPE_REQ 1 /* Echo Request. */
+#define GTPU_MSGTYPE_REPL 2 /* Echo Reply. */
+#define GTPU_MSGTYPE_GPDU 255 /* User Payload. */
+
+struct gtpu_metadata {
+ uint8_t flags;
+ uint8_t msgtype;
+};
+BUILD_ASSERT_DECL(sizeof(struct gtpu_metadata) == 2);
+
+struct gtpuhdr {
+ struct gtpu_metadata md;
+ ovs_be16 len;
+ ovs_16aligned_be32 teid;
+};
+BUILD_ASSERT_DECL(sizeof(struct gtpuhdr) == 8);
+
+struct gtpuhdr_opt {
+ ovs_be16 seqno;
+ uint8_t pdu_number;
+ uint8_t next_ext_type;
+};
+BUILD_ASSERT_DECL(sizeof(struct gtpuhdr_opt) == 4);
+
/* VXLAN protocol header */
struct vxlanhdr {
- ovs_16aligned_be32 vx_flags;
+ union {
+ ovs_16aligned_be32 vx_flags; /* VXLAN flags. */
+ struct {
+ uint8_t flags; /* VXLAN GPE flags. */
+ uint8_t reserved[2]; /* 16 bits reserved. */
+ uint8_t next_protocol; /* Next Protocol field for VXLAN GPE. */
+ } vx_gpe;
+ };
ovs_16aligned_be32 vx_vni;
};
+BUILD_ASSERT_DECL(sizeof(struct vxlanhdr) == 8);
#define VXLAN_FLAGS 0x08000000 /* struct vxlanhdr.vx_flags required value. */
+/*
+ * VXLAN Generic Protocol Extension (VXLAN_F_GPE):
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * |R|R|Ver|I|P|R|O| Reserved |Next Protocol |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ * | VXLAN Network Identifier (VNI) | Reserved |
+ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+ *
+ * Ver = Version. Indicates VXLAN GPE protocol version.
+ *
+ * P = Next Protocol Bit. The P bit is set to indicate that the
+ * Next Protocol field is present.
+ *
+ * O = OAM Flag Bit. The O bit is set to indicate that the packet
+ * is an OAM packet.
+ *
+ * Next Protocol = This 8 bit field indicates the protocol header
+ * immediately following the VXLAN GPE header.
+ *
+ * https://tools.ietf.org/html/draft-ietf-nvo3-vxlan-gpe-01
+ */
+
+/* Fields in struct vxlanhdr.vx_gpe.flags */
+#define VXLAN_GPE_FLAGS_VER 0x30 /* Version. */
+#define VLXAN_GPE_FLAGS_P 0x04 /* Next Protocol Bit. */
+#define VXLAN_GPE_FLAGS_O 0x01 /* OAM Bit. */
+
+/* VXLAN-GPE header flags. */
+#define VXLAN_HF_VER ((1U <<29) | (1U <<28))
+#define VXLAN_HF_NP (1U <<26)
+#define VXLAN_HF_OAM (1U <<24)
+
+#define VXLAN_GPE_USED_BITS (VXLAN_HF_VER | VXLAN_HF_NP | VXLAN_HF_OAM | \
+ 0xff)
+
+/* VXLAN-GPE header Next Protocol. */
+#define VXLAN_GPE_NP_IPV4 0x01
+#define VXLAN_GPE_NP_IPV6 0x02
+#define VXLAN_GPE_NP_ETHERNET 0x03
+#define VXLAN_GPE_NP_NSH 0x04
+
+#define VXLAN_F_GPE 0x4000
+#define VXLAN_HF_GPE 0x04000000
+
+/* Input values for PACKET_TYPE macros have to be in host byte order.
+ * The _BE postfix indicates result is in network byte order. Otherwise result
+ * is in host byte order. */
+#define PACKET_TYPE(NS, NS_TYPE) ((uint32_t) ((NS) << 16 | (NS_TYPE)))
+#define PACKET_TYPE_BE(NS, NS_TYPE) (htonl((NS) << 16 | (NS_TYPE)))
+
+/* Returns the host byte ordered namespace of 'packet type'. */
+static inline uint16_t
+pt_ns(ovs_be32 packet_type)
+{
+ return ntohl(packet_type) >> 16;
+}
+
+/* Returns the network byte ordered namespace type of 'packet type'. */
+static inline ovs_be16
+pt_ns_type_be(ovs_be32 packet_type)
+{
+ return be32_to_be16(packet_type);
+}
+
+/* Returns the host byte ordered namespace type of 'packet type'. */
+static inline uint16_t
+pt_ns_type(ovs_be32 packet_type)
+{
+ return ntohs(pt_ns_type_be(packet_type));
+}
+
+/* Well-known packet_type field values. */
+enum packet_type {
+ PT_ETH = PACKET_TYPE(OFPHTN_ONF, 0x0000), /* Default PT: Ethernet */
+ PT_USE_NEXT_PROTO = PACKET_TYPE(OFPHTN_ONF, 0xfffe), /* Pseudo PT for decap. */
+ PT_IPV4 = PACKET_TYPE(OFPHTN_ETHERTYPE, ETH_TYPE_IP),
+ PT_IPV6 = PACKET_TYPE(OFPHTN_ETHERTYPE, ETH_TYPE_IPV6),
+ PT_MPLS = PACKET_TYPE(OFPHTN_ETHERTYPE, ETH_TYPE_MPLS),
+ PT_MPLS_MC = PACKET_TYPE(OFPHTN_ETHERTYPE, ETH_TYPE_MPLS_MCAST),
+ PT_NSH = PACKET_TYPE(OFPHTN_ETHERTYPE, ETH_TYPE_NSH),
+ PT_UNKNOWN = PACKET_TYPE(0xffff, 0xffff), /* Unknown packet type. */
+};
+
+
void ipv6_format_addr(const struct in6_addr *addr, struct ds *);
void ipv6_format_addr_bracket(const struct in6_addr *addr, struct ds *,
bool bracket);
const char * ipv6_string_mapped(char *addr_str, const struct in6_addr *addr);
struct in6_addr ipv6_addr_bitand(const struct in6_addr *src,
const struct in6_addr *mask);
+struct in6_addr ipv6_addr_bitxor(const struct in6_addr *a,
+ const struct in6_addr *b);
+bool ipv6_is_zero(const struct in6_addr *a);
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);
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,
+void packet_set_ipv4_addr(struct dp_packet *packet, ovs_16aligned_be32 *addr,
+ ovs_be32 new_addr);
+void packet_set_ipv6(struct dp_packet *, const struct in6_addr *src,
+ const struct in6_addr *dst, uint8_t tc,
ovs_be32 fl, uint8_t hlmit);
+void packet_set_ipv6_addr(struct dp_packet *packet, uint8_t proto,
+ ovs_16aligned_be32 addr[4],
+ const struct in6_addr *new_addr,
+ bool recalculate_csum);
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_icmp(struct dp_packet *, uint8_t type, uint8_t code);
-void packet_set_nd(struct dp_packet *, const ovs_be32 target[4],
+void packet_set_nd(struct dp_packet *, const struct in6_addr *target,
const struct eth_addr sll, const struct eth_addr tll);
-
+void packet_set_nd_ext(struct dp_packet *packet,
+ const ovs_16aligned_be32 rso_flags,
+ const uint8_t opt_type);
+void packet_set_igmp3_query(struct dp_packet *, uint8_t max_resp,
+ ovs_be32 group, bool srs, uint8_t qrv,
+ uint8_t qqic);
void packet_format_tcp_flags(struct ds *, uint16_t);
const char *packet_tcp_flag_to_string(uint32_t flag);
+void *compose_ipv6(struct dp_packet *packet, uint8_t proto,
+ const struct in6_addr *src, const struct in6_addr *dst,
+ uint8_t key_tc, ovs_be32 key_fl, uint8_t key_hl, int size);
void compose_arp__(struct dp_packet *);
void compose_arp(struct dp_packet *, uint16_t arp_op,
const struct eth_addr arp_sha,
const struct eth_addr arp_tha, bool broadcast,
ovs_be32 arp_spa, ovs_be32 arp_tpa);
-void compose_nd(struct dp_packet *, const struct eth_addr eth_src,
- struct in6_addr *, struct in6_addr *);
+void compose_nd_ns(struct dp_packet *, const struct eth_addr eth_src,
+ const struct in6_addr *ipv6_src,
+ const struct in6_addr *ipv6_dst);
+void compose_nd_na(struct dp_packet *, const struct eth_addr eth_src,
+ const struct eth_addr eth_dst,
+ const struct in6_addr *ipv6_src,
+ const struct in6_addr *ipv6_dst,
+ ovs_be32 rso_flags);
+void compose_nd_ra(struct dp_packet *,
+ const struct eth_addr eth_src,
+ const struct eth_addr eth_dst,
+ const struct in6_addr *ipv6_src,
+ const struct in6_addr *ipv6_dst,
+ uint8_t cur_hop_limit, uint8_t mo_flags,
+ ovs_be16 router_lt, ovs_be32 reachable_time,
+ ovs_be32 retrans_timer, uint32_t mtu);
+void packet_put_ra_prefix_opt(struct dp_packet *,
+ uint8_t plen, uint8_t la_flags,
+ ovs_be32 valid_lifetime,
+ ovs_be32 preferred_lifetime,
+ const ovs_be128 router_prefix);
uint32_t packet_csum_pseudoheader(const struct ip_header *);
+void IP_ECN_set_ce(struct dp_packet *pkt, bool is_ipv6);
+
+#define DNS_HEADER_LEN 12
+struct dns_header {
+ ovs_be16 id;
+ uint8_t lo_flag; /* QR (1), OPCODE (4), AA (1), TC (1) and RD (1) */
+ uint8_t hi_flag; /* RA (1), Z (3) and RCODE (4) */
+ ovs_be16 qdcount; /* Num of entries in the question section. */
+ ovs_be16 ancount; /* Num of resource records in the answer section. */
+
+ /* Num of name server records in the authority record section. */
+ ovs_be16 nscount;
+
+ /* Num of resource records in the additional records section. */
+ ovs_be16 arcount;
+};
+
+BUILD_ASSERT_DECL(DNS_HEADER_LEN == sizeof(struct dns_header));
+
+#define DNS_QUERY_TYPE_A 0x01
+#define DNS_QUERY_TYPE_AAAA 0x1c
+#define DNS_QUERY_TYPE_ANY 0xff
+
+#define DNS_CLASS_IN 0x01
+#define DNS_DEFAULT_RR_TTL 3600
#endif /* packets.h */