2
0
mirror of https://github.com/openvswitch/ovs synced 2025-08-31 14:25:26 +00:00

userspace: add gre sequence number support.

The patch adds support for gre sequence number.
Default is disable.  When enable with 'options:seq=true',
the outgoing gre packet will have its sequence number
incremented by one.

Signed-off-by: William Tu <u9012063@gmail.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
This commit is contained in:
William Tu
2018-05-15 16:10:49 -04:00
committed by Ben Pfaff
parent 754f8acb45
commit 0ffff49753
5 changed files with 42 additions and 6 deletions

View File

@@ -436,10 +436,12 @@ err:
}
void
netdev_gre_push_header(const struct netdev *netdev OVS_UNUSED,
netdev_gre_push_header(const struct netdev *netdev,
struct dp_packet *packet,
const struct ovs_action_push_tnl *data)
{
struct netdev_vport *dev = netdev_vport_cast(netdev);
struct netdev_tunnel_config *tnl_cfg;
struct gre_base_hdr *greh;
int ip_tot_size;
@@ -449,6 +451,15 @@ netdev_gre_push_header(const struct netdev *netdev OVS_UNUSED,
ovs_be16 *csum_opt = (ovs_be16 *) (greh + 1);
*csum_opt = csum(greh, ip_tot_size);
}
if (greh->flags & htons(GRE_SEQ)) {
/* Last 4 byte is GRE seqno */
int seq_ofs = gre_header_len(greh->flags) - 4;
ovs_16aligned_be32 *seq_opt =
ALIGNED_CAST(ovs_16aligned_be32 *, (char *)greh + seq_ofs);
tnl_cfg = &dev->tnl_cfg;
put_16aligned_be32(seq_opt, htonl(tnl_cfg->seqno++));
}
}
int
@@ -491,6 +502,12 @@ netdev_gre_build_header(const struct netdev *netdev,
options++;
}
if (tnl_cfg->set_seq) {
greh->flags |= htons(GRE_SEQ);
/* seqno is updated at push header */
options++;
}
ovs_mutex_unlock(&dev->mutex);
hlen = (uint8_t *) options - (uint8_t *) greh;

View File

@@ -428,7 +428,7 @@ set_tunnel_config(struct netdev *dev_, const struct smap *args, char **errp)
const char *name = netdev_get_name(dev_);
const char *type = netdev_get_type(dev_);
struct ds errors = DS_EMPTY_INITIALIZER;
bool needs_dst_port, has_csum;
bool needs_dst_port, has_csum, has_seq;
uint16_t dst_proto = 0, src_proto = 0;
struct netdev_tunnel_config tnl_cfg;
struct smap_node *node;
@@ -436,6 +436,7 @@ set_tunnel_config(struct netdev *dev_, const struct smap *args, char **errp)
has_csum = strstr(type, "gre") || strstr(type, "geneve") ||
strstr(type, "stt") || strstr(type, "vxlan");
has_seq = strstr(type, "gre");
memset(&tnl_cfg, 0, sizeof tnl_cfg);
/* Add a default destination port for tunnel ports if none specified. */
@@ -506,6 +507,10 @@ set_tunnel_config(struct netdev *dev_, const struct smap *args, char **errp)
if (!strcmp(node->value, "true")) {
tnl_cfg.csum = true;
}
} else if (!strcmp(node->key, "seq") && has_seq) {
if (!strcmp(node->value, "true")) {
tnl_cfg.set_seq = true;
}
} else if (!strcmp(node->key, "df_default")) {
if (!strcmp(node->value, "false")) {
tnl_cfg.dont_fragment = false;
@@ -709,6 +714,10 @@ get_tunnel_config(const struct netdev *dev, struct smap *args)
smap_add(args, "csum", "true");
}
if (tnl_cfg.set_seq) {
smap_add(args, "seq", "true");
}
enum tunnel_layers layers = tunnel_supported_layers(type, &tnl_cfg);
if (tnl_cfg.pt_mode != default_pt_mode(layers)) {
smap_add(args, "packet_type",

View File

@@ -127,6 +127,9 @@ struct netdev_tunnel_config {
bool csum;
bool dont_fragment;
enum netdev_pt_mode pt_mode;
bool set_seq;
uint32_t seqno;
};
void netdev_run(void);

View File

@@ -358,7 +358,7 @@ AT_SETUP([tunnel_push_pop - underlay bridge match])
OVS_VSWITCHD_START([add-port br0 p0 -- set Interface p0 type=dummy ofport_request=1 other-config:hwaddr=aa:55:aa:55:00:00])
AT_CHECK([ovs-vsctl add-br int-br -- set bridge int-br datapath_type=dummy], [0])
AT_CHECK([ovs-vsctl add-port int-br t1 -- set Interface t1 type=gre \
options:remote_ip=1.1.2.92 options:key=456 ofport_request=3], [0])
options:remote_ip=1.1.2.92 options:key=456 options:seq=true ofport_request=3], [0])
AT_CHECK([ovs-appctl dpif/show], [0], [dnl
dummy@ovs-dummy: hit:0 missed:0
@@ -367,7 +367,7 @@ dummy@ovs-dummy: hit:0 missed:0
p0 1/1: (dummy)
int-br:
int-br 65534/2: (dummy-internal)
t1 3/3: (gre: key=456, remote_ip=1.1.2.92)
t1 3/3: (gre: key=456, remote_ip=1.1.2.92, seq=true)
])
AT_CHECK([ovs-appctl netdev-dummy/ip4addr br0 1.1.2.88/24], [0], [OK
@@ -390,14 +390,14 @@ AT_CHECK([ovs-ofctl add-flow int-br action=3])
AT_CHECK([ovs-appctl ofproto/trace ovs-dummy 'in_port(2),eth(src=f8:bc:12:44:34:b6,dst=aa:55:aa:55:00:00),eth_type(0x0800),ipv4(src=1.1.3.88,dst=1.1.3.112,proto=17,tos=0,ttl=64,frag=no),udp(src=51283,dst=4789)'], [0], [stdout])
AT_CHECK([tail -1 stdout], [0],
[Datapath actions: clone(tnl_push(tnl_port(3),header(size=42,type=3,eth(dst=f8:bc:12:44:34:b6,src=aa:55:aa:55:00:00,dl_type=0x0800),ipv4(src=1.1.2.88,dst=1.1.2.92,proto=47,tos=0,ttl=64,frag=0x4000),gre((flags=0x2000,proto=0x6558),key=0x1c8)),out_port(100)),1)
[Datapath actions: tnl_push(tnl_port(3),header(size=46,type=3,eth(dst=f8:bc:12:44:34:b6,src=aa:55:aa:55:00:00,dl_type=0x0800),ipv4(src=1.1.2.88,dst=1.1.2.92,proto=47,tos=0,ttl=64,frag=0x4000),gre((flags=0x3000,proto=0x6558),key=0x1c8,seq=0x0)),out_port(100))
])
dnl Verify outer L2 and L3 header flow fields can be matched in the underlay bridge
AT_CHECK([ovs-appctl netdev-dummy/receive int-br '50540000000a5054000000091234'])
AT_CHECK([ovs-ofctl dump-flows br0 | ofctl_strip | sort], [0], [dnl)
n_packets=1, n_bytes=42, priority=1,arp actions=NORMAL
n_packets=1, n_bytes=56, priority=99,ip,dl_src=aa:55:aa:55:00:00,dl_dst=f8:bc:12:44:34:b6,nw_src=1.1.2.88,nw_dst=1.1.2.92,nw_proto=47,nw_tos=0 actions=NORMAL
n_packets=1, n_bytes=60, priority=99,ip,dl_src=aa:55:aa:55:00:00,dl_dst=f8:bc:12:44:34:b6,nw_src=1.1.2.88,nw_dst=1.1.2.92,nw_proto=47,nw_tos=0 actions=NORMAL
NXST_FLOW reply:
])

View File

@@ -2596,6 +2596,13 @@
</li>
</ul>
</column>
<column name="options" key="seq" type='{"type": "boolean"}'>
<p>
Optional. A 4-byte sequence number field for GRE tunnel only.
Default is disabled, set to <code>true</code> to enable.
Sequence number is incremented by one on each outgoing packet.
</p>
</column>
</group>
<group title="Tunnel Options: gre, geneve, and vxlan">