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 {
4645struct 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);
7172static const char * tnl_port_get_name (const struct tnl_port * );
7273
7374static 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. */
120122struct 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(). */
131134bool
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 *
169175tnl_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 *
401407tnl_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)
450456static const char *
451457tnl_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}
0 commit comments