Skip to content

Commit e1939db

Browse files
committed
tunnel: Use ofport_dpif instead of ofport.
Necessary in a future patch. Signed-off-by: Ethan Jackson <ethan@nicira.com> Acked-by: Ben Pfaff <blp@nicira.com>
1 parent ea5e388 commit e1939db

3 files changed

Lines changed: 36 additions & 27 deletions

File tree

ofproto/ofproto-dpif.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ type_run(const char *type)
597597
}
598598

599599
iter->odp_port = node ? u32_to_odp(node->data) : ODPP_NONE;
600-
if (tnl_port_reconfigure(&iter->up, iter->odp_port,
600+
if (tnl_port_reconfigure(iter, iter->up.netdev, iter->odp_port,
601601
&iter->tnl_port)) {
602602
backer->need_revalidate = REV_RECONFIGURE;
603603
}
@@ -1486,7 +1486,7 @@ port_construct(struct ofport *port_)
14861486
port->odp_port = dpif_port.port_no;
14871487

14881488
if (netdev_get_tunnel_config(netdev)) {
1489-
port->tnl_port = tnl_port_add(&port->up, port->odp_port);
1489+
port->tnl_port = tnl_port_add(port, port->up.netdev, port->odp_port);
14901490
} else {
14911491
/* Sanity-check that a mapping doesn't already exist. This
14921492
* shouldn't happen for non-tunnel ports. */
@@ -1568,7 +1568,8 @@ port_modified(struct ofport *port_)
15681568
cfm_set_netdev(port->cfm, port->up.netdev);
15691569
}
15701570

1571-
if (port->tnl_port && tnl_port_reconfigure(&port->up, port->odp_port,
1571+
if (port->tnl_port && tnl_port_reconfigure(port, port->up.netdev,
1572+
port->odp_port,
15721573
&port->tnl_port)) {
15731574
ofproto_dpif_cast(port->up.ofproto)->backer->need_revalidate =
15741575
REV_RECONFIGURE;
@@ -3641,7 +3642,7 @@ ofproto_receive(const struct dpif_backer *backer, struct ofpbuf *packet,
36413642
}
36423643

36433644
port = (tnl_port_should_receive(flow)
3644-
? ofport_dpif_cast(tnl_port_receive(flow))
3645+
? tnl_port_receive(flow)
36453646
: odp_port_to_ofport(backer, flow->in_port.odp_port));
36463647
flow->in_port.ofp_port = port ? port->up.ofp_port : OFPP_NONE;
36473648
if (!port) {

ofproto/tunnel.c

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,11 @@
1717

1818
#include <errno.h>
1919

20-
#include "ofproto/ofproto-provider.h"
2120
#include "byte-order.h"
2221
#include "dynamic-string.h"
2322
#include "hash.h"
2423
#include "hmap.h"
25-
#include "netdev-vport.h"
24+
#include "netdev.h"
2625
#include "odp-util.h"
2726
#include "packets.h"
2827
#include "smap.h"
@@ -46,8 +45,10 @@ struct tnl_match {
4645
struct tnl_port {
4746
struct hmap_node match_node;
4847

49-
const struct ofport *ofport;
48+
const struct ofport_dpif *ofport;
5049
unsigned int netdev_seq;
50+
struct netdev *netdev;
51+
5152
struct tnl_match match;
5253
};
5354

@@ -71,19 +72,20 @@ static void tnl_port_mod_log(const struct tnl_port *, const char *action);
7172
static const char *tnl_port_get_name(const struct tnl_port *);
7273

7374
static struct tnl_port *
74-
tnl_port_add__(const struct ofport *ofport, odp_port_t odp_port,
75-
bool warn)
75+
tnl_port_add__(const struct ofport_dpif *ofport, const struct netdev *netdev,
76+
odp_port_t odp_port, bool warn)
7677
{
7778
const struct netdev_tunnel_config *cfg;
7879
struct tnl_port *existing_port;
7980
struct tnl_port *tnl_port;
8081

81-
cfg = netdev_get_tunnel_config(ofport->netdev);
82+
cfg = netdev_get_tunnel_config(netdev);
8283
ovs_assert(cfg);
8384

8485
tnl_port = xzalloc(sizeof *tnl_port);
8586
tnl_port->ofport = ofport;
86-
tnl_port->netdev_seq = netdev_change_seq(tnl_port->ofport->netdev);
87+
tnl_port->netdev = netdev_ref(netdev);
88+
tnl_port->netdev_seq = netdev_change_seq(tnl_port->netdev);
8789

8890
tnl_port->match.in_key = cfg->in_key;
8991
tnl_port->match.ip_src = cfg->ip_src;
@@ -118,9 +120,10 @@ tnl_port_add__(const struct ofport *ofport, odp_port_t odp_port,
118120
* must be added before they can be used by the module. 'ofport' must be a
119121
* tunnel. */
120122
struct tnl_port *
121-
tnl_port_add(const struct ofport *ofport, odp_port_t odp_port)
123+
tnl_port_add(const struct ofport_dpif *ofport, const struct netdev *netdev,
124+
odp_port_t odp_port)
122125
{
123-
return tnl_port_add__(ofport, odp_port, true);
126+
return tnl_port_add__(ofport, netdev, odp_port, true);
124127
}
125128

126129
/* Checks if the tnl_port pointed to by 'tnl_portp' needs reconfiguration due
@@ -129,20 +132,22 @@ tnl_port_add(const struct ofport *ofport, odp_port_t odp_port)
129132
* 'ofport' and 'odp_port' should be the same as would be passed to
130133
* tnl_port_add(). */
131134
bool
132-
tnl_port_reconfigure(const struct ofport *ofport, odp_port_t odp_port,
135+
tnl_port_reconfigure(const struct ofport_dpif *ofport,
136+
const struct netdev *netdev, odp_port_t odp_port,
133137
struct tnl_port **tnl_portp)
134138
{
135139
struct tnl_port *tnl_port = *tnl_portp;
136140

137141
if (tnl_port == &void_tnl_port) {
138-
*tnl_portp = tnl_port_add__(ofport, odp_port, false);
142+
*tnl_portp = tnl_port_add__(ofport, netdev, odp_port, false);
139143
return *tnl_portp != &void_tnl_port;
140144
} else if (tnl_port->ofport != ofport
145+
|| tnl_port->netdev != netdev
141146
|| tnl_port->match.odp_port != odp_port
142-
|| tnl_port->netdev_seq != netdev_change_seq(ofport->netdev)) {
147+
|| tnl_port->netdev_seq != netdev_change_seq(netdev)) {
143148
VLOG_DBG("reconfiguring %s", tnl_port_get_name(tnl_port));
144149
tnl_port_del(tnl_port);
145-
*tnl_portp = tnl_port_add(ofport, odp_port);
150+
*tnl_portp = tnl_port_add(ofport, netdev, odp_port);
146151
return true;
147152
}
148153
return false;
@@ -155,6 +160,7 @@ tnl_port_del(struct tnl_port *tnl_port)
155160
if (tnl_port && tnl_port != &void_tnl_port) {
156161
tnl_port_mod_log(tnl_port, "removing");
157162
hmap_remove(&tnl_match_map, &tnl_port->match_node);
163+
netdev_close(tnl_port->netdev);
158164
free(tnl_port);
159165
}
160166
}
@@ -165,7 +171,7 @@ tnl_port_del(struct tnl_port *tnl_port)
165171
*
166172
* Callers should verify that 'flow' needs to be received by calling
167173
* tnl_port_should_receive() before this function. */
168-
const struct ofport *
174+
const struct ofport_dpif *
169175
tnl_port_receive(const struct flow *flow)
170176
{
171177
char *pre_flow_str = NULL;
@@ -223,7 +229,7 @@ tnl_port_send(const struct tnl_port *tnl_port, struct flow *flow,
223229
return ODPP_NONE;
224230
}
225231

226-
cfg = netdev_get_tunnel_config(tnl_port->ofport->netdev);
232+
cfg = netdev_get_tunnel_config(tnl_port->netdev);
227233
ovs_assert(cfg);
228234

229235
if (!VLOG_DROP_DBG(&dbg_rl)) {
@@ -401,12 +407,12 @@ static char *
401407
tnl_port_fmt(const struct tnl_port *tnl_port)
402408
{
403409
const struct netdev_tunnel_config *cfg =
404-
netdev_get_tunnel_config(tnl_port->ofport->netdev);
410+
netdev_get_tunnel_config(tnl_port->netdev);
405411
struct ds ds = DS_EMPTY_INITIALIZER;
406412

407413
ds_put_format(&ds, "port %"PRIu32": %s (%s: ", tnl_port->match.odp_port,
408414
tnl_port_get_name(tnl_port),
409-
netdev_get_type(tnl_port->ofport->netdev));
415+
netdev_get_type(tnl_port->netdev));
410416
tnl_match_fmt(&tnl_port->match, &ds);
411417

412418
if (cfg->out_key != cfg->in_key ||
@@ -450,5 +456,5 @@ tnl_port_fmt(const struct tnl_port *tnl_port)
450456
static const char *
451457
tnl_port_get_name(const struct tnl_port *tnl_port)
452458
{
453-
return netdev_get_name(tnl_port->ofport->netdev);
459+
return netdev_get_name(tnl_port->netdev);
454460
}

ofproto/tunnel.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,18 @@
2828
* These functions emulate tunnel virtual ports based on the outer
2929
* header information from the kernel. */
3030

31-
struct ofport;
31+
struct ofport_dpif;
32+
struct netdev;
3233
struct tnl_port;
3334

34-
bool tnl_port_reconfigure(const struct ofport *, odp_port_t odp_port,
35-
struct tnl_port **);
35+
bool tnl_port_reconfigure(const struct ofport_dpif *, const struct netdev *,
36+
odp_port_t, struct tnl_port **);
3637

37-
struct tnl_port *tnl_port_add(const struct ofport *, odp_port_t odp_port);
38+
struct tnl_port *tnl_port_add(const struct ofport_dpif *, const struct netdev *,
39+
odp_port_t);
3840
void tnl_port_del(struct tnl_port *);
3941

40-
const struct ofport *tnl_port_receive(const struct flow *);
42+
const struct ofport_dpif *tnl_port_receive(const struct flow *);
4143
odp_port_t tnl_port_send(const struct tnl_port *, struct flow *,
4244
struct flow_wildcards *wc);
4345

0 commit comments

Comments
 (0)