From fa8223b7fd02890647eb2bf3d3b5b27ee4d32a21 Mon Sep 17 00:00:00 2001 From: Justin Pettit Date: Tue, 1 Nov 2011 15:57:56 -0700 Subject: [PATCH] Support matching IPv6 flow label. Signed-off-by: Justin Pettit Acked-by: Jesse Gross --- NEWS | 3 ++- datapath/flow.c | 7 +++++-- datapath/flow.h | 7 ++++--- include/linux/openvswitch.h | 1 + include/openflow/nicira-ext.h | 9 +++++++++ lib/classifier.c | 16 +++++++++++++--- lib/classifier.h | 1 + lib/flow.c | 19 ++++++++++++------- lib/flow.h | 17 +++++++++-------- lib/meta-flow.c | 31 +++++++++++++++++++++++++++++++ lib/meta-flow.h | 2 ++ lib/nx-match.c | 12 +++++++++++- lib/nx-match.def | 1 + lib/nx-match.h | 3 ++- lib/odp-util.c | 16 ++++++++++------ lib/odp-util.h | 6 +++--- lib/ofp-util.c | 13 ++++++++++--- lib/packets.h | 3 +++ tests/odp.at | 20 ++++++++++---------- tests/ovs-ofctl.at | 4 ++++ utilities/ovs-ofctl.8.in | 4 ++++ 21 files changed, 147 insertions(+), 48 deletions(-) diff --git a/NEWS b/NEWS index 41e224d5..51e00cf6 100644 --- a/NEWS +++ b/NEWS @@ -1,9 +1,10 @@ post-v1.3.0 ------------------------ + - OpenFlow: + - Added ability to match on IPv6 flow label through NXM. - ovs-appctl: - New "fdb/flush" command to flush bridge's MAC learning table. - v1.3.0 - xx xxx xxxx ------------------------ - OpenFlow: diff --git a/datapath/flow.c b/datapath/flow.c index 2dc87aee..a7832a43 100644 --- a/datapath/flow.c +++ b/datapath/flow.c @@ -190,7 +190,7 @@ static int parse_ipv6hdr(struct sk_buff *skb, struct sw_flow_key *key, uint8_t nexthdr; int err; - *key_lenp = SW_FLOW_KEY_OFFSET(ipv6.addr); + *key_lenp = SW_FLOW_KEY_OFFSET(ipv6.label); err = check_header(skb, nh_ofs + sizeof(*nh)); if (unlikely(err)) @@ -202,6 +202,7 @@ static int parse_ipv6hdr(struct sk_buff *skb, struct sw_flow_key *key, key->ip.proto = NEXTHDR_NONE; key->ip.tos_frag = ipv6_get_dsfield(nh) & ~INET_ECN_MASK; + key->ipv6.label = *(__be32 *)nh & htonl(IPV6_FLOWINFO_FLOWLABEL); ipv6_addr_copy(&key->ipv6.addr.src, &nh->saddr); ipv6_addr_copy(&key->ipv6.addr.dst, &nh->daddr); @@ -978,10 +979,11 @@ int flow_from_nlattrs(struct sw_flow_key *swkey, int *key_lenp, break; case TRANSITION(OVS_KEY_ATTR_ETHERTYPE, OVS_KEY_ATTR_IPV6): - key_len = SW_FLOW_KEY_OFFSET(ipv6.addr); + key_len = SW_FLOW_KEY_OFFSET(ipv6.label); if (swkey->eth.type != htons(ETH_P_IPV6)) goto invalid; ipv6_key = nla_data(nla); + swkey->ipv6.label = ipv6_key->ipv6_label; swkey->ip.proto = ipv6_key->ipv6_proto; if (parse_tos_frag(swkey, ipv6_key->ipv6_tos, ipv6_key->ipv6_frag)) @@ -1268,6 +1270,7 @@ int flow_to_nlattrs(const struct sw_flow_key *swkey, struct sk_buff *skb) sizeof(ipv6_key->ipv6_src)); memcpy(ipv6_key->ipv6_dst, &swkey->ipv6.addr.dst, sizeof(ipv6_key->ipv6_dst)); + ipv6_key->ipv6_label = swkey->ipv6.label; ipv6_key->ipv6_proto = swkey->ip.proto; ipv6_key->ipv6_tos = swkey->ip.tos_frag & ~INET_ECN_MASK; ipv6_key->ipv6_frag = swkey->ip.tos_frag & OVS_FRAG_TYPE_MASK; diff --git a/datapath/flow.h b/datapath/flow.h index 5bd8c8da..0471cfc5 100644 --- a/datapath/flow.h +++ b/datapath/flow.h @@ -73,6 +73,7 @@ struct sw_flow_key { struct in6_addr src; /* IPv6 source address. */ struct in6_addr dst; /* IPv6 destination address. */ } addr; + __be32 label; /* IPv6 flow label. */ struct { __be16 src; /* TCP/UDP source port. */ __be16 dst; /* TCP/UDP destination port. */ @@ -146,13 +147,13 @@ u64 flow_used_time(unsigned long flow_jiffies); * OVS_KEY_ATTR_ETHERNET 12 -- 4 16 * OVS_KEY_ATTR_8021Q 4 -- 4 8 * OVS_KEY_ATTR_ETHERTYPE 2 2 4 8 - * OVS_KEY_ATTR_IPV6 34 2 4 40 + * OVS_KEY_ATTR_IPV6 38 2 4 44 * OVS_KEY_ATTR_ICMPV6 2 2 4 8 * OVS_KEY_ATTR_ND 28 -- 4 32 * ------------------------------------------------- - * total 140 + * total 144 */ -#define FLOW_BUFSIZE 140 +#define FLOW_BUFSIZE 144 int flow_to_nlattrs(const struct sw_flow_key *, struct sk_buff *); int flow_from_nlattrs(struct sw_flow_key *swkey, int *key_lenp, diff --git a/include/linux/openvswitch.h b/include/linux/openvswitch.h index 1ce2a1e0..62668a62 100644 --- a/include/linux/openvswitch.h +++ b/include/linux/openvswitch.h @@ -322,6 +322,7 @@ struct ovs_key_ipv4 { struct ovs_key_ipv6 { __be32 ipv6_src[4]; __be32 ipv6_dst[4]; + __be32 ipv6_label; /* 20-bits in least-significant bits. */ __u8 ipv6_proto; __u8 ipv6_tos; __u8 ipv6_frag; /* One of OVS_FRAG_TYPE_*. */ diff --git a/include/openflow/nicira-ext.h b/include/openflow/nicira-ext.h index 875052a9..394d43d1 100644 --- a/include/openflow/nicira-ext.h +++ b/include/openflow/nicira-ext.h @@ -1614,6 +1614,15 @@ OFP_ASSERT(sizeof(struct nx_action_output_reg) == 24); #define NX_IP_FRAG_ANY (1 << 0) /* Is this a fragment? */ #define NX_IP_FRAG_LATER (1 << 1) /* Is this a fragment with nonzero offset? */ +/* The flow label in the IPv6 header. + * + * Prereqs: NXM_OF_ETH_TYPE must match 0x86dd exactly. + * + * Format: 20-bit IPv6 flow label in least-significant bits. + * + * Masking: Not maskable. */ +#define NXM_NX_IPV6_LABEL NXM_HEADER (0x0001, 27, 4) + /* ## --------------------- ## */ /* ## Requests and replies. ## */ /* ## --------------------- ## */ diff --git a/lib/classifier.c b/lib/classifier.c index 8ffc96f5..7d7a4498 100644 --- a/lib/classifier.c +++ b/lib/classifier.c @@ -347,7 +347,6 @@ cls_rule_set_icmp_type(struct cls_rule *rule, uint8_t icmp_type) { rule->wc.wildcards &= ~FWW_TP_SRC; rule->flow.tp_src = htons(icmp_type); - } void @@ -407,6 +406,13 @@ cls_rule_set_ipv6_dst_masked(struct cls_rule *rule, const struct in6_addr *dst, } } +void +cls_rule_set_ipv6_label(struct cls_rule *rule, ovs_be32 ipv6_label) +{ + rule->wc.wildcards &= ~FWW_IPV6_LABEL; + rule->flow.ipv6_label = ipv6_label; +} + void cls_rule_set_nd_target(struct cls_rule *rule, const struct in6_addr *target) { @@ -469,7 +475,7 @@ cls_rule_format(const struct cls_rule *rule, struct ds *s) int i; - BUILD_ASSERT_DECL(FLOW_WC_SEQ == 3); + BUILD_ASSERT_DECL(FLOW_WC_SEQ == 4); if (rule->priority != OFP_DEFAULT_PRIORITY) { ds_put_format(s, "priority=%d,", rule->priority); @@ -590,6 +596,9 @@ cls_rule_format(const struct cls_rule *rule, struct ds *s) if (f->dl_type == htons(ETH_TYPE_IPV6)) { format_ipv6_netmask(s, "ipv6_src", &f->ipv6_src, &wc->ipv6_src_mask); format_ipv6_netmask(s, "ipv6_dst", &f->ipv6_dst, &wc->ipv6_dst_mask); + if (!(w & FWW_IPV6_LABEL)) { + ds_put_format(s, "ipv6_label=0x%05"PRIx32",", ntohl(f->ipv6_label)); + } } else { format_ip_netmask(s, "nw_src", f->nw_src, wc->nw_src_mask); format_ip_netmask(s, "nw_dst", f->nw_dst, wc->nw_dst_mask); @@ -1160,7 +1169,7 @@ flow_equal_except(const struct flow *a, const struct flow *b, const flow_wildcards_t wc = wildcards->wildcards; int i; - BUILD_ASSERT_DECL(FLOW_WC_SEQ == 3); + BUILD_ASSERT_DECL(FLOW_WC_SEQ == 4); for (i = 0; i < FLOW_N_REGS; i++) { if ((a->regs[i] ^ b->regs[i]) & wildcards->reg_masks[i]) { @@ -1190,6 +1199,7 @@ flow_equal_except(const struct flow *a, const struct flow *b, && !((a->tos_frag ^ b->tos_frag) & wildcards->tos_frag_mask) && (wc & FWW_ARP_SHA || eth_addr_equals(a->arp_sha, b->arp_sha)) && (wc & FWW_ARP_THA || eth_addr_equals(a->arp_tha, b->arp_tha)) + && (wc & FWW_IPV6_LABEL || a->ipv6_label == b->ipv6_label) && ipv6_equal_except(&a->ipv6_src, &b->ipv6_src, &wildcards->ipv6_src_mask) && ipv6_equal_except(&a->ipv6_dst, &b->ipv6_dst, diff --git a/lib/classifier.h b/lib/classifier.h index d5c19f09..a61d0e69 100644 --- a/lib/classifier.h +++ b/lib/classifier.h @@ -129,6 +129,7 @@ bool cls_rule_set_ipv6_src_masked(struct cls_rule *, const struct in6_addr *, void cls_rule_set_ipv6_dst(struct cls_rule *, const struct in6_addr *); bool cls_rule_set_ipv6_dst_masked(struct cls_rule *, const struct in6_addr *, const struct in6_addr *); +void cls_rule_set_ipv6_label(struct cls_rule *, ovs_be32); void cls_rule_set_nd_target(struct cls_rule *, const struct in6_addr *); bool cls_rule_equal(const struct cls_rule *, const struct cls_rule *); diff --git a/lib/flow.c b/lib/flow.c index 1263734b..9323aae7 100644 --- a/lib/flow.c +++ b/lib/flow.c @@ -149,6 +149,7 @@ parse_ipv6(struct ofpbuf *packet, struct flow *flow) tc_flow = get_unaligned_be32(&nh->ip6_flow); flow->tos_frag = (ntohl(tc_flow) >> 4) & IP_DSCP_MASK; + flow->ipv6_label = tc_flow & htonl(IPV6_LABEL_MASK); flow->nw_proto = IPPROTO_NONE; while (1) { @@ -437,7 +438,7 @@ flow_zero_wildcards(struct flow *flow, const struct flow_wildcards *wildcards) const flow_wildcards_t wc = wildcards->wildcards; int i; - BUILD_ASSERT_DECL(FLOW_WC_SEQ == 3); + BUILD_ASSERT_DECL(FLOW_WC_SEQ == 4); for (i = 0; i < FLOW_N_REGS; i++) { flow->regs[i] &= wildcards->reg_masks[i]; @@ -471,6 +472,9 @@ flow_zero_wildcards(struct flow *flow, const struct flow_wildcards *wildcards) if (wc & FWW_NW_PROTO) { flow->nw_proto = 0; } + if (wc & FWW_IPV6_LABEL) { + flow->ipv6_label = htonl(0); + } flow->tos_frag &= wildcards->tos_frag_mask; if (wc & FWW_ARP_SHA) { memset(flow->arp_sha, 0, sizeof flow->arp_sha); @@ -523,8 +527,9 @@ flow_format(struct ds *ds, const struct flow *flow) ntohs(flow->dl_type)); if (flow->dl_type == htons(ETH_TYPE_IPV6)) { - ds_put_format(ds, " proto%"PRIu8" tos%"PRIu8" ipv6", - flow->nw_proto, flow->tos_frag & IP_DSCP_MASK); + ds_put_format(ds, " label%#"PRIx32" proto%"PRIu8" tos%"PRIu8" ipv6", + ntohl(flow->ipv6_label), flow->nw_proto, + flow->tos_frag & IP_DSCP_MASK); print_ipv6_addr(ds, &flow->ipv6_src); ds_put_cstr(ds, "->"); print_ipv6_addr(ds, &flow->ipv6_dst); @@ -570,7 +575,7 @@ flow_print(FILE *stream, const struct flow *flow) void flow_wildcards_init_catchall(struct flow_wildcards *wc) { - BUILD_ASSERT_DECL(FLOW_WC_SEQ == 3); + BUILD_ASSERT_DECL(FLOW_WC_SEQ == 4); wc->wildcards = FWW_ALL; wc->tun_id_mask = htonll(0); @@ -589,7 +594,7 @@ flow_wildcards_init_catchall(struct flow_wildcards *wc) void flow_wildcards_init_exact(struct flow_wildcards *wc) { - BUILD_ASSERT_DECL(FLOW_WC_SEQ == 3); + BUILD_ASSERT_DECL(FLOW_WC_SEQ == 4); wc->wildcards = 0; wc->tun_id_mask = htonll(UINT64_MAX); @@ -610,7 +615,7 @@ flow_wildcards_is_exact(const struct flow_wildcards *wc) { int i; - BUILD_ASSERT_DECL(FLOW_WC_SEQ == 3); + BUILD_ASSERT_DECL(FLOW_WC_SEQ == 4); if (wc->wildcards || wc->tun_id_mask != htonll(UINT64_MAX) @@ -639,7 +644,7 @@ flow_wildcards_is_catchall(const struct flow_wildcards *wc) { int i; - BUILD_ASSERT_DECL(FLOW_WC_SEQ == 3); + BUILD_ASSERT_DECL(FLOW_WC_SEQ == 4); if (wc->wildcards != FWW_ALL || wc->tun_id_mask != htonll(0) diff --git a/lib/flow.h b/lib/flow.h index ff440a23..c4510737 100644 --- a/lib/flow.h +++ b/lib/flow.h @@ -35,7 +35,7 @@ struct ofpbuf; /* This sequence number should be incremented whenever anything involving flows * or the wildcarding of flows changes. This will cause build assertion * failures in places which likely need to be updated. */ -#define FLOW_WC_SEQ 3 +#define FLOW_WC_SEQ 4 #define FLOW_N_REGS 5 BUILD_ASSERT_DECL(FLOW_N_REGS <= NXM_NX_MAX_REGS); @@ -61,6 +61,7 @@ struct flow { uint32_t regs[FLOW_N_REGS]; /* Registers. */ ovs_be32 nw_src; /* IPv4 source address. */ ovs_be32 nw_dst; /* IPv4 destination address. */ + ovs_be32 ipv6_label; /* IPv6 flow label. */ uint16_t in_port; /* OpenFlow port number of input port. */ ovs_be16 vlan_tci; /* If 802.1Q, TCI | VLAN_CFI; otherwise 0. */ ovs_be16 dl_type; /* Ethernet frame type. */ @@ -72,19 +73,18 @@ struct flow { uint8_t tos_frag; /* IP ToS in top bits, FLOW_FRAG_* in low. */ uint8_t arp_sha[6]; /* ARP/ND source hardware address. */ uint8_t arp_tha[6]; /* ARP/ND target hardware address. */ - uint32_t reserved; /* Reserved for 64-bit packing. */ }; /* Assert that there are FLOW_SIG_SIZE bytes of significant data in "struct * flow", followed by FLOW_PAD_SIZE bytes of padding. */ -#define FLOW_SIG_SIZE (104 + FLOW_N_REGS * 4) -#define FLOW_PAD_SIZE 4 +#define FLOW_SIG_SIZE (108 + FLOW_N_REGS * 4) +#define FLOW_PAD_SIZE 0 BUILD_ASSERT_DECL(offsetof(struct flow, arp_tha) == FLOW_SIG_SIZE - 6); BUILD_ASSERT_DECL(sizeof(((struct flow *)0)->arp_tha) == 6); BUILD_ASSERT_DECL(sizeof(struct flow) == FLOW_SIG_SIZE + FLOW_PAD_SIZE); /* Remember to update FLOW_WC_SEQ when changing 'struct flow'. */ -BUILD_ASSERT_DECL(FLOW_SIG_SIZE == 124 && FLOW_WC_SEQ == 3); +BUILD_ASSERT_DECL(FLOW_SIG_SIZE == 128 && FLOW_WC_SEQ == 4); void flow_extract(struct ofpbuf *, uint32_t priority, ovs_be64 tun_id, uint16_t in_port, struct flow *); @@ -140,10 +140,11 @@ typedef unsigned int OVS_BITWISE flow_wildcards_t; #define FWW_ARP_SHA ((OVS_FORCE flow_wildcards_t) (1 << 8)) #define FWW_ARP_THA ((OVS_FORCE flow_wildcards_t) (1 << 9)) #define FWW_ND_TARGET ((OVS_FORCE flow_wildcards_t) (1 << 10)) -#define FWW_ALL ((OVS_FORCE flow_wildcards_t) (((1 << 11)) - 1)) +#define FWW_IPV6_LABEL ((OVS_FORCE flow_wildcards_t) (1 << 11)) +#define FWW_ALL ((OVS_FORCE flow_wildcards_t) (((1 << 12)) - 1)) /* Remember to update FLOW_WC_SEQ when adding or removing FWW_*. */ -BUILD_ASSERT_DECL(FWW_ALL == ((1 << 11) - 1) && FLOW_WC_SEQ == 3); +BUILD_ASSERT_DECL(FWW_ALL == ((1 << 12) - 1) && FLOW_WC_SEQ == 4); /* Information on wildcards for a flow, as a supplement to "struct flow". * @@ -163,7 +164,7 @@ struct flow_wildcards { }; /* Remember to update FLOW_WC_SEQ when updating struct flow_wildcards. */ -BUILD_ASSERT_DECL(sizeof(struct flow_wildcards) == 80 && FLOW_WC_SEQ == 3); +BUILD_ASSERT_DECL(sizeof(struct flow_wildcards) == 80 && FLOW_WC_SEQ == 4); void flow_wildcards_init_catchall(struct flow_wildcards *); void flow_wildcards_init_exact(struct flow_wildcards *); diff --git a/lib/meta-flow.c b/lib/meta-flow.c index 0f00996d..4bf6039f 100644 --- a/lib/meta-flow.c +++ b/lib/meta-flow.c @@ -171,6 +171,14 @@ static const struct mf_field mf_fields[MFF_N_IDS] = { MFP_IPV6, NXM_NX_IPV6_DST, }, + { + MFF_IPV6_LABEL, "ipv6_label", NULL, + 4, 20, + MFM_NONE, FWW_IPV6_LABEL, + MFS_HEXADECIMAL, + MFP_IPV6, + NXM_NX_IPV6_LABEL, + }, { MFF_IP_PROTO, "nw_proto", NULL, @@ -354,6 +362,7 @@ mf_is_all_wild(const struct mf_field *mf, const struct flow_wildcards *wc) case MFF_ETH_SRC: case MFF_ETH_TYPE: case MFF_IP_PROTO: + case MFF_IPV6_LABEL: case MFF_ARP_OP: case MFF_ARP_SHA: case MFF_ARP_THA: @@ -444,6 +453,7 @@ mf_get_mask(const struct mf_field *mf, const struct flow_wildcards *wc, case MFF_ETH_SRC: case MFF_ETH_TYPE: case MFF_IP_PROTO: + case MFF_IPV6_LABEL: case MFF_ARP_OP: case MFF_ARP_SHA: case MFF_ARP_THA: @@ -696,6 +706,9 @@ mf_is_value_valid(const struct mf_field *mf, const union mf_value *value) case MFF_VLAN_PCP: return !(value->u8 & ~7); + case MFF_IPV6_LABEL: + return !(value->be32 & ~htonl(IPV6_LABEL_MASK)); + case MFF_N_IDS: default: NOT_REACHED(); @@ -778,6 +791,10 @@ mf_get_value(const struct mf_field *mf, const struct flow *flow, value->ipv6 = flow->ipv6_dst; break; + case MFF_IPV6_LABEL: + value->be32 = flow->ipv6_label; + break; + case MFF_IP_PROTO: value->u8 = flow->nw_proto; break; @@ -925,6 +942,10 @@ mf_set_value(const struct mf_field *mf, cls_rule_set_ipv6_dst(rule, &value->ipv6); break; + case MFF_IPV6_LABEL: + cls_rule_set_ipv6_label(rule, value->be32); + break; + case MFF_IP_PROTO: cls_rule_set_nw_proto(rule, value->u8); break; @@ -1086,6 +1107,11 @@ mf_set_wild(const struct mf_field *mf, struct cls_rule *rule) memset(&rule->flow.ipv6_dst, 0, sizeof rule->flow.ipv6_dst); break; + case MFF_IPV6_LABEL: + rule->wc.wildcards |= FWW_IPV6_LABEL; + rule->flow.ipv6_label = 0; + break; + case MFF_IP_PROTO: rule->wc.wildcards |= FWW_NW_PROTO; rule->flow.nw_proto = 0; @@ -1173,6 +1199,7 @@ mf_set(const struct mf_field *mf, case MFF_ETH_TYPE: case MFF_VLAN_VID: case MFF_VLAN_PCP: + case MFF_IPV6_LABEL: case MFF_IP_PROTO: case MFF_IP_TOS: case MFF_ARP_OP: @@ -1393,6 +1420,10 @@ mf_random_value(const struct mf_field *mf, union mf_value *value) case MFF_ND_TLL: break; + case MFF_IPV6_LABEL: + value->be32 &= ~htonl(IPV6_LABEL_MASK); + break; + case MFF_IP_TOS: value->u8 &= ~0x03; break; diff --git a/lib/meta-flow.h b/lib/meta-flow.h index 9f3b2eec..54dead87 100644 --- a/lib/meta-flow.h +++ b/lib/meta-flow.h @@ -67,6 +67,7 @@ enum mf_field_id { MFF_IPV6_SRC, /* ipv6 */ MFF_IPV6_DST, /* ipv6 */ + MFF_IPV6_LABEL, /* be32 */ MFF_IP_PROTO, /* u8 (used for IPv4 or IPv6) */ MFF_IP_TOS, /* u8 (used for IPv4 or IPv6) */ @@ -162,6 +163,7 @@ struct mf_field { * - "dl_vlan" is 2 bytes but only 12 bits. * - "dl_vlan_pcp" is 1 byte but only 3 bits. * - "is_frag" is 1 byte but only 2 bits. + * - "ipv6_label" is 4 bytes but only 20 bits. */ unsigned int n_bytes; /* Width of the field in bytes. */ unsigned int n_bits; /* Number of significant bits in field. */ diff --git a/lib/nx-match.c b/lib/nx-match.c index 84a14de3..e6259889 100644 --- a/lib/nx-match.c +++ b/lib/nx-match.c @@ -466,7 +466,7 @@ nx_put_match(struct ofpbuf *b, const struct cls_rule *cr) int match_len; int i; - BUILD_ASSERT_DECL(FLOW_WC_SEQ == 3); + BUILD_ASSERT_DECL(FLOW_WC_SEQ == 4); /* Metadata. */ if (!(wc & FWW_IN_PORT)) { @@ -535,6 +535,9 @@ nx_put_match(struct ofpbuf *b, const struct cls_rule *cr) &cr->wc.ipv6_src_mask); nxm_put_ipv6(b, NXM_NX_IPV6_DST, &flow->ipv6_dst, &cr->wc.ipv6_dst_mask); + if (!(wc & FWW_IPV6_LABEL)) { + nxm_put_32(b, NXM_NX_IPV6_LABEL, flow->ipv6_label); + } if (!(wc & FWW_NW_PROTO)) { nxm_put_8(b, NXM_OF_IP_PROTO, flow->nw_proto); @@ -1075,6 +1078,9 @@ nxm_read_field(const struct nxm_field *src, const struct flow *flow) case NFI_NXM_NX_TUN_ID: return ntohll(flow->tun_id); + case NFI_NXM_NX_IPV6_LABEL: + return ntohl(flow->ipv6_label); + #define NXM_READ_REGISTER(IDX) \ case NFI_NXM_NX_REG##IDX: \ return flow->regs[IDX]; \ @@ -1206,6 +1212,10 @@ nxm_write_field(const struct nxm_field *dst, struct flow *flow, flow->nw_dst = htonl(new_value); break; + case NFI_NXM_NX_IPV6_LABEL: + flow->ipv6_label = htonl(new_value); + break; + case NFI_NXM_OF_TCP_SRC: case NFI_NXM_OF_UDP_SRC: flow->tp_src = htons(new_value); diff --git a/lib/nx-match.def b/lib/nx-match.def index 5c0a2383..89efdad6 100644 --- a/lib/nx-match.def +++ b/lib/nx-match.def @@ -44,6 +44,7 @@ DEFINE_FIELD (NX_ARP_SHA, MFF_ARP_SHA, false) DEFINE_FIELD (NX_ARP_THA, MFF_ARP_THA, false) DEFINE_FIELD_M(NX_IPV6_SRC, MFF_IPV6_SRC, false) DEFINE_FIELD_M(NX_IPV6_DST, MFF_IPV6_DST, false) +DEFINE_FIELD (NX_IPV6_LABEL, MFF_IPV6_LABEL,false) /* XXX should we have MFF_ICMPV4_TYPE and MFF_ICMPV6_TYPE? */ DEFINE_FIELD (NX_ICMPV6_TYPE,MFF_ICMP_TYPE, false) DEFINE_FIELD (NX_ICMPV6_CODE,MFF_ICMP_CODE, false) diff --git a/lib/nx-match.h b/lib/nx-match.h index fbb8946b..346604e4 100644 --- a/lib/nx-match.h +++ b/lib/nx-match.h @@ -106,6 +106,7 @@ nxm_decode_n_bits(ovs_be16 ofs_nbits) * NXM_OF_IP_PROTO 4 2 -- 6 * NXM_OF_IPV6_SRC_W 4 16 16 36 * NXM_OF_IPV6_DST_W 4 16 16 36 + * NXM_OF_IPV6_LABEL 4 4 -- 8 * NXM_OF_ICMP_TYPE 4 1 -- 5 * NXM_OF_ICMP_CODE 4 1 -- 5 * NXM_NX_ND_TARGET 4 16 -- 20 @@ -117,7 +118,7 @@ nxm_decode_n_bits(ovs_be16 ofs_nbits) * NXM_NX_REG_W(4) 4 4 4 12 * NXM_NX_TUN_ID_W 4 8 8 20 * ------------------------------------------- - * total 257 + * total 265 * * So this value is conservative. */ diff --git a/lib/odp-util.c b/lib/odp-util.c index 1e9289a7..51cd001f 100644 --- a/lib/odp-util.c +++ b/lib/odp-util.c @@ -385,10 +385,10 @@ format_odp_key_attr(const struct nlattr *a, struct ds *ds) inet_ntop(AF_INET6, ipv6_key->ipv6_src, src_str, sizeof src_str); inet_ntop(AF_INET6, ipv6_key->ipv6_dst, dst_str, sizeof dst_str); - ds_put_format(ds, "ipv6(src=%s,dst=%s,proto=%"PRId8",tos=%"PRIu8"," - "frag=%s)", - src_str, dst_str, ipv6_key->ipv6_proto, - ipv6_key->ipv6_tos, + ds_put_format(ds, "ipv6(src=%s,dst=%s,label=%#"PRIx32",proto=%"PRId8 + ",tos=%"PRIu8",frag=%s)", + src_str, dst_str, ntohl(ipv6_key->ipv6_label), + ipv6_key->ipv6_proto, ipv6_key->ipv6_tos, ovs_frag_type_to_string(ipv6_key->ipv6_frag)); break; } @@ -633,6 +633,7 @@ parse_odp_key_attr(const char *s, struct ofpbuf *key) { char ipv6_src_s[IPV6_SCAN_LEN + 1]; char ipv6_dst_s[IPV6_SCAN_LEN + 1]; + int ipv6_label; int ipv6_proto; int ipv6_tos; char frag[8]; @@ -640,8 +641,8 @@ parse_odp_key_attr(const char *s, struct ofpbuf *key) int n = -1; if (sscanf(s, "ipv6(src="IPV6_SCAN_FMT",dst="IPV6_SCAN_FMT"," - "proto=%i,tos=%i,frag=%7[a-z])%n", - ipv6_src_s, ipv6_dst_s, + "label=%i,proto=%i,tos=%i,frag=%7[a-z])%n", + ipv6_src_s, ipv6_dst_s, &ipv6_label, &ipv6_proto, &ipv6_tos, frag, &n) > 0 && n > 0 && ovs_frag_type_from_string(frag, &ipv6_frag)) { @@ -652,6 +653,7 @@ parse_odp_key_attr(const char *s, struct ofpbuf *key) inet_pton(AF_INET6, ipv6_dst_s, &ipv6_key.ipv6_dst) != 1) { return -EINVAL; } + ipv6_key.ipv6_label = htonl(ipv6_label); ipv6_key.ipv6_proto = ipv6_proto; ipv6_key.ipv6_tos = ipv6_tos; ipv6_key.ipv6_frag = ipv6_frag; @@ -884,6 +886,7 @@ odp_flow_key_from_flow(struct ofpbuf *buf, const struct flow *flow) memset(ipv6_key, 0, sizeof *ipv6_key); memcpy(ipv6_key->ipv6_src, &flow->ipv6_src, sizeof ipv6_key->ipv6_src); memcpy(ipv6_key->ipv6_dst, &flow->ipv6_dst, sizeof ipv6_key->ipv6_dst); + ipv6_key->ipv6_label = flow->ipv6_label; ipv6_key->ipv6_proto = flow->nw_proto; ipv6_key->ipv6_tos = flow->tos_frag & IP_DSCP_MASK; ipv6_key->ipv6_frag = tos_frag_to_odp_frag(flow->tos_frag); @@ -1071,6 +1074,7 @@ odp_flow_key_to_flow(const struct nlattr *key, size_t key_len, ipv6_key = nl_attr_get(nla); memcpy(&flow->ipv6_src, ipv6_key->ipv6_src, sizeof flow->ipv6_src); memcpy(&flow->ipv6_dst, ipv6_key->ipv6_dst, sizeof flow->ipv6_dst); + flow->ipv6_label = ipv6_key->ipv6_label; flow->nw_proto = ipv6_key->ipv6_proto; if (!odp_to_tos_frag(ipv6_key->ipv6_tos, ipv6_key->ipv6_frag, flow)) { diff --git a/lib/odp-util.h b/lib/odp-util.h index c916abf8..8a7fbc63 100644 --- a/lib/odp-util.h +++ b/lib/odp-util.h @@ -72,13 +72,13 @@ void format_odp_actions(struct ds *, const struct nlattr *odp_actions, * OVS_KEY_ATTR_ETHERNET 12 -- 4 16 * OVS_KEY_ATTR_8021Q 4 -- 4 8 * OVS_KEY_ATTR_ETHERTYPE 2 2 4 8 - * OVS_KEY_ATTR_IPV6 34 2 4 40 + * OVS_KEY_ATTR_IPV6 38 2 4 44 * OVS_KEY_ATTR_ICMPV6 2 2 4 8 * OVS_KEY_ATTR_ND 28 -- 4 32 * ------------------------------------------------- - * total 140 + * total 144 */ -#define ODPUTIL_FLOW_KEY_BYTES 140 +#define ODPUTIL_FLOW_KEY_BYTES 144 /* A buffer with sufficient size and alignment to hold an nlattr-formatted flow * key. An array of "struct nlattr" might not, in theory, be sufficiently diff --git a/lib/ofp-util.c b/lib/ofp-util.c index af831a02..d8bee057 100644 --- a/lib/ofp-util.c +++ b/lib/ofp-util.c @@ -101,14 +101,15 @@ static const flow_wildcards_t WC_INVARIANTS = 0 void ofputil_wildcard_from_openflow(uint32_t ofpfw, struct flow_wildcards *wc) { - BUILD_ASSERT_DECL(FLOW_WC_SEQ == 3); + BUILD_ASSERT_DECL(FLOW_WC_SEQ == 4); /* Initialize most of rule->wc. */ flow_wildcards_init_catchall(wc); wc->wildcards = (OVS_FORCE flow_wildcards_t) ofpfw & WC_INVARIANTS; /* Wildcard fields that aren't defined by ofp_match or tun_id. */ - wc->wildcards |= (FWW_ARP_SHA | FWW_ARP_THA | FWW_ND_TARGET); + wc->wildcards |= (FWW_ARP_SHA | FWW_ARP_THA | FWW_ND_TARGET + | FWW_IPV6_LABEL); if (!(ofpfw & OFPFW_NW_TOS)) { wc->tos_frag_mask |= IP_DSCP_MASK; @@ -858,7 +859,7 @@ ofputil_min_flow_format(const struct cls_rule *rule) { const struct flow_wildcards *wc = &rule->wc; - BUILD_ASSERT_DECL(FLOW_WC_SEQ == 3); + BUILD_ASSERT_DECL(FLOW_WC_SEQ == 4); /* Only NXM supports separately wildcards the Ethernet multicast bit. */ if (!(wc->wildcards & FWW_DL_DST) != !(wc->wildcards & FWW_ETH_MCAST)) { @@ -891,6 +892,11 @@ ofputil_min_flow_format(const struct cls_rule *rule) return NXFF_NXM; } + /* Only NXM supports matching IPv6 flow label. */ + if (!(wc->wildcards & FWW_IPV6_LABEL)) { + return NXFF_NXM; + } + /* Other formats can express this rule. */ return NXFF_OPENFLOW10; } @@ -2567,6 +2573,7 @@ ofputil_normalize_rule(struct cls_rule *rule, enum nx_flow_format flow_format) } if (!(may_match & MAY_IPV6_ADDR)) { wc.ipv6_src_mask = wc.ipv6_dst_mask = in6addr_any; + wc.wildcards |= FWW_IPV6_LABEL; } if (!(may_match & MAY_ND_TARGET)) { wc.wildcards |= FWW_ND_TARGET; diff --git a/lib/packets.h b/lib/packets.h index 84877541..d9244928 100644 --- a/lib/packets.h +++ b/lib/packets.h @@ -392,6 +392,9 @@ struct arp_eth_header { } __attribute__((packed)); BUILD_ASSERT_DECL(ARP_ETH_HEADER_LEN == sizeof(struct arp_eth_header)); +/* 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"; diff --git a/tests/odp.at b/tests/odp.at index f7cdf9dc..384e2d95 100644 --- a/tests/odp.at +++ b/tests/odp.at @@ -10,16 +10,16 @@ in_port(1),eth(src=00:01:02:03:04:05,dst=10:11:12:13:14:15),eth_type(0x0800),ipv in_port(1),eth(src=00:01:02:03:04:05,dst=10:11:12:13:14:15),eth_type(0x0800),ipv4(src=35.8.2.41,dst=172.16.0.20,proto=6,tos=0,frag=no),tcp(src=80,dst=8080) in_port(1),eth(src=00:01:02:03:04:05,dst=10:11:12:13:14:15),eth_type(0x0800),ipv4(src=35.8.2.41,dst=172.16.0.20,proto=17,tos=0,frag=no),udp(src=81,dst=6632) in_port(1),eth(src=00:01:02:03:04:05,dst=10:11:12:13:14:15),eth_type(0x0800),ipv4(src=35.8.2.41,dst=172.16.0.20,proto=1,tos=0,frag=no),icmp(type=1,code=2) -in_port(1),eth(src=00:01:02:03:04:05,dst=10:11:12:13:14:15),eth_type(0x86dd),ipv6(src=::1,dst=::2,proto=10,tos=112,frag=no) -in_port(1),eth(src=00:01:02:03:04:05,dst=10:11:12:13:14:15),eth_type(0x86dd),ipv6(src=::1,dst=::2,proto=10,tos=112,frag=first) -in_port(1),eth(src=00:01:02:03:04:05,dst=10:11:12:13:14:15),eth_type(0x86dd),ipv6(src=::1,dst=::2,proto=10,tos=112,frag=later) -in_port(1),eth(src=00:01:02:03:04:05,dst=10:11:12:13:14:15),eth_type(0x86dd),ipv6(src=::1,dst=::2,proto=6,tos=0,frag=no),tcp(src=80,dst=8080) -in_port(1),eth(src=00:01:02:03:04:05,dst=10:11:12:13:14:15),eth_type(0x86dd),ipv6(src=::1,dst=::2,proto=17,tos=0,frag=no),udp(src=6630,dst=22) -in_port(1),eth(src=00:01:02:03:04:05,dst=10:11:12:13:14:15),eth_type(0x86dd),ipv6(src=::1,dst=::2,proto=58,tos=0,frag=no),icmpv6(type=1,code=2) -in_port(1),eth(src=00:01:02:03:04:05,dst=10:11:12:13:14:15),eth_type(0x86dd),ipv6(src=::1,dst=::2,proto=58,tos=0,frag=no),icmpv6(type=135,code=0),nd(target=::3) -in_port(1),eth(src=00:01:02:03:04:05,dst=10:11:12:13:14:15),eth_type(0x86dd),ipv6(src=::1,dst=::2,proto=58,tos=0,frag=no),icmpv6(type=135,code=0),nd(target=::3,sll=00:05:06:07:08:09) -in_port(1),eth(src=00:01:02:03:04:05,dst=10:11:12:13:14:15),eth_type(0x86dd),ipv6(src=::1,dst=::2,proto=58,tos=0,frag=no),icmpv6(type=136,code=0),nd(target=::3,tll=00:0a:0b:0c:0d:0e) -in_port(1),eth(src=00:01:02:03:04:05,dst=10:11:12:13:14:15),eth_type(0x86dd),ipv6(src=::1,dst=::2,proto=58,tos=0,frag=no),icmpv6(type=136,code=0),nd(target=::3,sll=00:05:06:07:08:09,tll=00:0a:0b:0c:0d:0e) +in_port(1),eth(src=00:01:02:03:04:05,dst=10:11:12:13:14:15),eth_type(0x86dd),ipv6(src=::1,dst=::2,label=0,proto=10,tos=112,frag=no) +in_port(1),eth(src=00:01:02:03:04:05,dst=10:11:12:13:14:15),eth_type(0x86dd),ipv6(src=::1,dst=::2,label=0,proto=10,tos=112,frag=first) +in_port(1),eth(src=00:01:02:03:04:05,dst=10:11:12:13:14:15),eth_type(0x86dd),ipv6(src=::1,dst=::2,label=0,proto=10,tos=112,frag=later) +in_port(1),eth(src=00:01:02:03:04:05,dst=10:11:12:13:14:15),eth_type(0x86dd),ipv6(src=::1,dst=::2,label=0,proto=6,tos=0,frag=no),tcp(src=80,dst=8080) +in_port(1),eth(src=00:01:02:03:04:05,dst=10:11:12:13:14:15),eth_type(0x86dd),ipv6(src=::1,dst=::2,label=0,proto=17,tos=0,frag=no),udp(src=6630,dst=22) +in_port(1),eth(src=00:01:02:03:04:05,dst=10:11:12:13:14:15),eth_type(0x86dd),ipv6(src=::1,dst=::2,label=0,proto=58,tos=0,frag=no),icmpv6(type=1,code=2) +in_port(1),eth(src=00:01:02:03:04:05,dst=10:11:12:13:14:15),eth_type(0x86dd),ipv6(src=::1,dst=::2,label=0,proto=58,tos=0,frag=no),icmpv6(type=135,code=0),nd(target=::3) +in_port(1),eth(src=00:01:02:03:04:05,dst=10:11:12:13:14:15),eth_type(0x86dd),ipv6(src=::1,dst=::2,label=0,proto=58,tos=0,frag=no),icmpv6(type=135,code=0),nd(target=::3,sll=00:05:06:07:08:09) +in_port(1),eth(src=00:01:02:03:04:05,dst=10:11:12:13:14:15),eth_type(0x86dd),ipv6(src=::1,dst=::2,label=0,proto=58,tos=0,frag=no),icmpv6(type=136,code=0),nd(target=::3,tll=00:0a:0b:0c:0d:0e) +in_port(1),eth(src=00:01:02:03:04:05,dst=10:11:12:13:14:15),eth_type(0x86dd),ipv6(src=::1,dst=::2,label=0,proto=58,tos=0,frag=no),icmpv6(type=136,code=0),nd(target=::3,sll=00:05:06:07:08:09,tll=00:0a:0b:0c:0d:0e) in_port(1),eth(src=00:01:02:03:04:05,dst=10:11:12:13:14:15),eth_type(0x0806),arp(sip=1.2.3.4,tip=5.6.7.8,op=1,sha=00:0f:10:11:12:13,tha=00:14:15:16:17:18) ]) diff --git a/tests/ovs-ofctl.at b/tests/ovs-ofctl.at index d2bf7f70..23a4d8c5 100644 --- a/tests/ovs-ofctl.at +++ b/tests/ovs-ofctl.at @@ -67,6 +67,7 @@ AT_DATA([flows.txt], [ tcp,tp_src=123,actions=flood in_port=LOCAL dl_vlan=9 dl_src=00:0A:E4:25:6B:B0 actions=drop arp,dl_src=00:0A:E4:25:6B:B0,arp_sha=00:0A:E4:25:6B:B0 actions=drop +ipv6,ipv6_label=0x12345 actions=2 ipv6,ipv6_src=2001:db8:3c4d:1:2:3:4:5 actions=3 ipv6,ipv6_src=2001:db8:3c4d:1:2:3:4:5/64 actions=4 ipv6,ipv6_dst=2001:db8:3c4d:1:2:3:4:5/127 actions=5 @@ -94,6 +95,7 @@ AT_CHECK([[sed 's/ (xid=0x[0-9a-fA-F]*)//' stdout]], [0], [dnl NXT_FLOW_MOD: ADD tcp,tp_src=123 actions=FLOOD NXT_FLOW_MOD: ADD in_port=65534,dl_vlan=9,dl_src=00:0a:e4:25:6b:b0 actions=drop NXT_FLOW_MOD: ADD arp,dl_src=00:0a:e4:25:6b:b0,arp_sha=00:0a:e4:25:6b:b0 actions=drop +NXT_FLOW_MOD: ADD ipv6,ipv6_label=0x12345 actions=output:2 NXT_FLOW_MOD: ADD ipv6,ipv6_src=2001:db8:3c4d:1:2:3:4:5 actions=output:3 NXT_FLOW_MOD: ADD ipv6,ipv6_src=2001:db8:3c4d:1::/64 actions=output:4 NXT_FLOW_MOD: ADD ipv6,ipv6_dst=2001:db8:3c4d:1:2:3:4:4/127 actions=output:5 @@ -124,6 +126,7 @@ AT_DATA([flows.txt], [[ tcp,tp_src=123,actions=flood in_port=LOCAL dl_vlan=9 dl_src=00:0A:E4:25:6B:B0 actions=drop arp,dl_src=00:0A:E4:25:6B:B0,arp_sha=00:0A:E4:25:6B:B0 actions=drop +ipv6,ipv6_label=0x12345 actions=2 ipv6,ipv6_src=2001:db8:3c4d:1:2:3:4:5 actions=3 ipv6,ipv6_src=2001:db8:3c4d:1:2:3:4:5/64 actions=4 ipv6,ipv6_dst=2001:db8:3c4d:1:2:3:4:5/127 actions=5 @@ -149,6 +152,7 @@ AT_CHECK([[sed 's/ (xid=0x[0-9a-fA-F]*)//' stdout]], [0], [[NXT_FLOW_MOD: ADD NXM_OF_ETH_TYPE(0800), NXM_OF_IP_PROTO(06), NXM_OF_TCP_SRC(007b) actions=FLOOD NXT_FLOW_MOD: ADD NXM_OF_IN_PORT(fffe), NXM_OF_ETH_SRC(000ae4256bb0), NXM_OF_VLAN_TCI_W(1009/1fff) actions=drop NXT_FLOW_MOD: ADD NXM_OF_ETH_SRC(000ae4256bb0), NXM_OF_ETH_TYPE(0806), NXM_NX_ARP_SHA(000ae4256bb0) actions=drop +NXT_FLOW_MOD: ADD NXM_OF_ETH_TYPE(86dd), NXM_NX_IPV6_LABEL(00012345) actions=output:2 NXT_FLOW_MOD: ADD NXM_OF_ETH_TYPE(86dd), NXM_NX_IPV6_SRC(20010db83c4d00010002000300040005) actions=output:3 NXT_FLOW_MOD: ADD NXM_OF_ETH_TYPE(86dd), NXM_NX_IPV6_SRC_W(20010db83c4d00010000000000000000/ffffffffffffffff0000000000000000) actions=output:4 NXT_FLOW_MOD: ADD NXM_OF_ETH_TYPE(86dd), NXM_NX_IPV6_DST_W(20010db83c4d00010002000300040004/fffffffffffffffffffffffffffffffe) actions=output:5 diff --git a/utilities/ovs-ofctl.8.in b/utilities/ovs-ofctl.8.in index ee2caf2f..2bf37403 100644 --- a/utilities/ovs-ofctl.8.in +++ b/utilities/ovs-ofctl.8.in @@ -548,6 +548,10 @@ groups of 16-bits of zeros. The optional \fInetmask\fR allows restricting a match to an IPv6 address prefix. A netmask is specified as a CIDR block (e.g. \fB2001:db8:3c4d:1::/64\fR). . +.IP \fBipv6_label=\fIlabel\fR +When \fBdl_type\fR is 0x86dd (possibly via shorthand, e.g., \fBipv6\fR +or \fBtcp6\fR), matches IPv6 flow label \fIlabel\fR. +. .IP \fBnd_target=\fIipv6\fR When \fBdl_type\fR, \fBnw_proto\fR, and \fBicmp_type\fR specify IPv6 Neighbor Discovery (ICMPv6 type 135 or 136), matches the target address -- 2.30.2