1 /* Copyright (c) 2013, 2014, 2015, 2017 Nicira, Inc.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License. */
20 #include "byte-order.h"
21 #include "connectivity.h"
24 #include "openvswitch/dynamic-string.h"
25 #include "fat-rwlock.h"
27 #include "openvswitch/hmap.h"
30 #include "openvswitch/ofpbuf.h"
32 #include "route-table.h"
35 #include "socket-util.h"
36 #include "tnl-ports.h"
38 #include "openvswitch/vlog.h"
39 #include "unaligned.h"
41 #include "ofproto-dpif.h"
42 #include "netdev-vport.h"
44 VLOG_DEFINE_THIS_MODULE(tunnel
);
48 struct in6_addr ipv6_src
;
49 struct in6_addr ipv6_dst
;
54 enum netdev_pt_mode pt_mode
;
58 struct hmap_node ofport_node
;
59 struct hmap_node match_node
;
61 const struct ofport_dpif
*ofport
;
63 struct netdev
*netdev
;
65 struct tnl_match match
;
68 static struct fat_rwlock rwlock
;
72 * This module maps packets received over tunnel protocols to vports. The
73 * tunnel protocol and, for some protocols, tunnel-specific information (e.g.,
74 * for VXLAN, the UDP destination port number) are always use as part of the
75 * mapping. Which other fields are used for the mapping depends on the vports
76 * themselves (the parenthesized notations refer to "struct tnl_match" fields):
78 * - in_key: A vport may match a specific tunnel ID (in_key_flow == false)
79 * or arrange for the tunnel ID to be matched as tunnel.tun_id in the
80 * OpenFlow flow (in_key_flow == true).
82 * - ip_dst: A vport may match a specific destination IP address
83 * (ip_dst_flow == false) or arrange for the destination IP to be matched
84 * as tunnel.ip_dst in the OpenFlow flow (ip_dst_flow == true).
86 * - ip_src: A vport may match a specific IP source address (ip_src_flow ==
87 * false, ip_src != 0), wildcard all source addresses (ip_src_flow ==
88 * false, ip_src == 0), or arrange for the IP source address to be
89 * handled in the OpenFlow flow table (ip_src_flow == true).
91 * Thus, there are 2 * 2 * 3 == 12 possible ways a vport can match against a
92 * tunnel packet. We number the possibilities for each field in increasing
93 * order as listed in each bullet above. We order the 12 overall combinations
94 * in lexicographic order considering in_key first, then ip_dst, then
96 #define N_MATCH_TYPES (2 * 2 * 3)
98 /* The three possibilities (see above) for vport ip_src matches. */
100 IP_SRC_CFG
, /* ip_src must equal configured address. */
101 IP_SRC_ANY
, /* Any ip_src is acceptable. */
102 IP_SRC_FLOW
/* ip_src is handled in flow table. */
105 /* Each hmap contains "struct tnl_port"s.
106 * The index is a combination of how each of the fields listed under "Tunnel
107 * matches" above matches, see the final paragraph for ordering. */
108 static struct hmap
*tnl_match_maps
[N_MATCH_TYPES
] OVS_GUARDED_BY(rwlock
);
109 static struct hmap
**tnl_match_map(const struct tnl_match
*);
111 static struct hmap ofport_map__
= HMAP_INITIALIZER(&ofport_map__
);
112 static struct hmap
*ofport_map
OVS_GUARDED_BY(rwlock
) = &ofport_map__
;
114 static struct vlog_rate_limit rl
= VLOG_RATE_LIMIT_INIT(1, 5);
115 static struct vlog_rate_limit dbg_rl
= VLOG_RATE_LIMIT_INIT(60, 60);
117 static struct tnl_port
*tnl_find(const struct flow
*) OVS_REQ_RDLOCK(rwlock
);
118 static struct tnl_port
*tnl_find_exact(struct tnl_match
*, struct hmap
*)
119 OVS_REQ_RDLOCK(rwlock
);
120 static struct tnl_port
*tnl_find_ofport(const struct ofport_dpif
*)
121 OVS_REQ_RDLOCK(rwlock
);
123 static uint32_t tnl_hash(struct tnl_match
*);
124 static void tnl_match_fmt(const struct tnl_match
*, struct ds
*);
125 static char *tnl_port_to_string(const struct tnl_port
*)
126 OVS_REQ_RDLOCK(rwlock
);
127 static void tnl_port_format(const struct tnl_port
*, struct ds
*)
128 OVS_REQ_RDLOCK(rwlock
);
129 static void tnl_port_mod_log(const struct tnl_port
*, const char *action
)
130 OVS_REQ_RDLOCK(rwlock
);
131 static const char *tnl_port_get_name(const struct tnl_port
*)
132 OVS_REQ_RDLOCK(rwlock
);
133 static void tnl_port_del__(const struct ofport_dpif
*, odp_port_t
)
134 OVS_REQ_WRLOCK(rwlock
);
136 static unixctl_cb_func tnl_unixctl_list
;
139 ofproto_tunnel_init(void)
141 static struct ovsthread_once once
= OVSTHREAD_ONCE_INITIALIZER
;
143 if (ovsthread_once_start(&once
)) {
144 fat_rwlock_init(&rwlock
);
145 unixctl_command_register("ofproto/list-tunnels", "", 0, 0,
146 tnl_unixctl_list
, NULL
);
147 ovsthread_once_done(&once
);
152 tnl_port_add__(const struct ofport_dpif
*ofport
, const struct netdev
*netdev
,
153 odp_port_t odp_port
, bool warn
, bool native_tnl
, const char name
[])
154 OVS_REQ_WRLOCK(rwlock
)
156 const struct netdev_tunnel_config
*cfg
;
157 struct tnl_port
*existing_port
;
158 struct tnl_port
*tnl_port
;
161 cfg
= netdev_get_tunnel_config(netdev
);
164 tnl_port
= xzalloc(sizeof *tnl_port
);
165 tnl_port
->ofport
= ofport
;
166 tnl_port
->netdev
= netdev_ref(netdev
);
167 tnl_port
->change_seq
= netdev_get_change_seq(tnl_port
->netdev
);
169 tnl_port
->match
.in_key
= cfg
->in_key
;
170 tnl_port
->match
.ipv6_src
= cfg
->ipv6_src
;
171 tnl_port
->match
.ipv6_dst
= cfg
->ipv6_dst
;
172 tnl_port
->match
.ip_src_flow
= cfg
->ip_src_flow
;
173 tnl_port
->match
.ip_dst_flow
= cfg
->ip_dst_flow
;
174 tnl_port
->match
.in_key_flow
= cfg
->in_key_flow
;
175 tnl_port
->match
.odp_port
= odp_port
;
176 tnl_port
->match
.pt_mode
= netdev_get_pt_mode(netdev
);
178 map
= tnl_match_map(&tnl_port
->match
);
179 existing_port
= tnl_find_exact(&tnl_port
->match
, *map
);
182 struct ds ds
= DS_EMPTY_INITIALIZER
;
183 tnl_match_fmt(&tnl_port
->match
, &ds
);
184 VLOG_WARN("%s: attempting to add tunnel port with same config as "
185 "port '%s' (%s)", tnl_port_get_name(tnl_port
),
186 tnl_port_get_name(existing_port
), ds_cstr(&ds
));
189 netdev_close(tnl_port
->netdev
);
194 hmap_insert(ofport_map
, &tnl_port
->ofport_node
, hash_pointer(ofport
, 0));
197 *map
= xmalloc(sizeof **map
);
200 hmap_insert(*map
, &tnl_port
->match_node
, tnl_hash(&tnl_port
->match
));
201 tnl_port_mod_log(tnl_port
, "adding");
206 type
= netdev_get_type(netdev
);
207 tnl_port_map_insert(odp_port
, cfg
->dst_port
, name
, type
);
213 /* Adds 'ofport' to the module with datapath port number 'odp_port'. 'ofport's
214 * must be added before they can be used by the module. 'ofport' must be a
217 * Returns 0 if successful, otherwise a positive errno value. */
219 tnl_port_add(const struct ofport_dpif
*ofport
, const struct netdev
*netdev
,
220 odp_port_t odp_port
, bool native_tnl
, const char name
[])
225 fat_rwlock_wrlock(&rwlock
);
226 ok
= tnl_port_add__(ofport
, netdev
, odp_port
, true, native_tnl
, name
);
227 fat_rwlock_unlock(&rwlock
);
229 return ok
? 0 : EEXIST
;
232 /* Checks if the tunnel represented by 'ofport' reconfiguration due to changes
233 * in its netdev_tunnel_config. If it does, returns true. Otherwise, returns
234 * false. 'new_odp_port' should be the port number coming from 'ofport' that
235 * is passed to tnl_port_add__(). 'old_odp_port' should be the port number
236 * that is passed to tnl_port_del__(). */
238 tnl_port_reconfigure(const struct ofport_dpif
*ofport
,
239 const struct netdev
*netdev
, odp_port_t new_odp_port
,
240 odp_port_t old_odp_port
, bool native_tnl
,
244 struct tnl_port
*tnl_port
;
245 bool changed
= false;
247 fat_rwlock_wrlock(&rwlock
);
248 tnl_port
= tnl_find_ofport(ofport
);
250 changed
= tnl_port_add__(ofport
, netdev
, new_odp_port
, false,
252 } else if (tnl_port
->netdev
!= netdev
253 || tnl_port
->match
.odp_port
!= new_odp_port
254 || tnl_port
->change_seq
!= netdev_get_change_seq(tnl_port
->netdev
)) {
255 VLOG_DBG("reconfiguring %s", tnl_port_get_name(tnl_port
));
256 tnl_port_del__(ofport
, old_odp_port
);
257 tnl_port_add__(ofport
, netdev
, new_odp_port
, true, native_tnl
, name
);
260 fat_rwlock_unlock(&rwlock
);
265 tnl_port_del__(const struct ofport_dpif
*ofport
, odp_port_t odp_port
)
266 OVS_REQ_WRLOCK(rwlock
)
268 struct tnl_port
*tnl_port
;
274 tnl_port
= tnl_find_ofport(ofport
);
278 tnl_port_map_delete(odp_port
, netdev_get_type(tnl_port
->netdev
));
279 tnl_port_mod_log(tnl_port
, "removing");
280 map
= tnl_match_map(&tnl_port
->match
);
281 hmap_remove(*map
, &tnl_port
->match_node
);
282 if (hmap_is_empty(*map
)) {
287 hmap_remove(ofport_map
, &tnl_port
->ofport_node
);
288 netdev_close(tnl_port
->netdev
);
293 /* Removes 'ofport' from the module. */
295 tnl_port_del(const struct ofport_dpif
*ofport
, odp_port_t odp_port
)
298 fat_rwlock_wrlock(&rwlock
);
299 tnl_port_del__(ofport
, odp_port
);
300 fat_rwlock_unlock(&rwlock
);
303 /* Looks in the table of tunnels for a tunnel matching the metadata in 'flow'.
304 * Returns the 'ofport' corresponding to the new in_port, or a null pointer if
307 * Callers should verify that 'flow' needs to be received by calling
308 * tnl_port_should_receive() before this function. */
309 const struct ofport_dpif
*
310 tnl_port_receive(const struct flow
*flow
) OVS_EXCLUDED(rwlock
)
312 const struct ofport_dpif
*ofport
;
313 struct tnl_port
*tnl_port
;
315 fat_rwlock_rdlock(&rwlock
);
316 tnl_port
= tnl_find(flow
);
317 ofport
= tnl_port
? tnl_port
->ofport
: NULL
;
319 if (!VLOG_DROP_WARN(&rl
)) {
320 char *flow_str
= flow_to_string(flow
, NULL
);
321 VLOG_WARN("receive tunnel port not found (%s)", flow_str
);
327 if (!VLOG_DROP_DBG(&dbg_rl
)) {
328 char *flow_str
= flow_to_string(flow
, NULL
);
329 char *tnl_str
= tnl_port_to_string(tnl_port
);
330 VLOG_DBG("tunnel port %s receive from flow %s", tnl_str
, flow_str
);
336 fat_rwlock_unlock(&rwlock
);
340 /* Should be called at the beginning of action translation to initialize
341 * wildcards and perform any actions based on receiving on tunnel port.
343 * Returns false if the packet must be dropped. */
345 tnl_process_ecn(struct flow
*flow
)
347 if (!tnl_port_should_receive(flow
)) {
351 if (is_ip_any(flow
) && IP_ECN_is_ce(flow
->tunnel
.ip_tos
)) {
352 if ((flow
->nw_tos
& IP_ECN_MASK
) == IP_ECN_NOT_ECT
) {
353 VLOG_WARN_RL(&rl
, "dropping tunnel packet marked ECN CE"
354 " but is not ECN capable");
358 /* Set the ECN CE value in the tunneled packet. */
359 flow
->nw_tos
|= IP_ECN_CE
;
366 tnl_wc_init(struct flow
*flow
, struct flow_wildcards
*wc
)
368 if (tnl_port_should_receive(flow
)) {
369 wc
->masks
.tunnel
.tun_id
= OVS_BE64_MAX
;
370 if (flow
->tunnel
.ip_dst
) {
371 wc
->masks
.tunnel
.ip_src
= OVS_BE32_MAX
;
372 wc
->masks
.tunnel
.ip_dst
= OVS_BE32_MAX
;
374 wc
->masks
.tunnel
.ipv6_src
= in6addr_exact
;
375 wc
->masks
.tunnel
.ipv6_dst
= in6addr_exact
;
377 wc
->masks
.tunnel
.flags
= (FLOW_TNL_F_DONT_FRAGMENT
|
380 wc
->masks
.tunnel
.ip_tos
= UINT8_MAX
;
381 wc
->masks
.tunnel
.ip_ttl
= 0;
382 /* The tp_src and tp_dst members in flow_tnl are set to be always
383 * wildcarded, not to unwildcard them here. */
384 wc
->masks
.tunnel
.tp_src
= 0;
385 wc
->masks
.tunnel
.tp_dst
= 0;
388 && IP_ECN_is_ce(flow
->tunnel
.ip_tos
)) {
389 wc
->masks
.nw_tos
|= IP_ECN_MASK
;
394 /* Given that 'flow' should be output to the ofport corresponding to
395 * 'tnl_port', updates 'flow''s tunnel headers and returns the actual datapath
396 * port that the output should happen on. May return ODPP_NONE if the output
397 * shouldn't occur. */
399 tnl_port_send(const struct ofport_dpif
*ofport
, struct flow
*flow
,
400 struct flow_wildcards
*wc
) OVS_EXCLUDED(rwlock
)
402 const struct netdev_tunnel_config
*cfg
;
403 struct tnl_port
*tnl_port
;
404 char *pre_flow_str
= NULL
;
407 fat_rwlock_rdlock(&rwlock
);
408 tnl_port
= tnl_find_ofport(ofport
);
409 out_port
= tnl_port
? tnl_port
->match
.odp_port
: ODPP_NONE
;
414 cfg
= netdev_get_tunnel_config(tnl_port
->netdev
);
417 if (!VLOG_DROP_DBG(&dbg_rl
)) {
418 pre_flow_str
= flow_to_string(flow
, NULL
);
421 if (!cfg
->ip_src_flow
) {
422 flow
->tunnel
.ip_src
= in6_addr_get_mapped_ipv4(&tnl_port
->match
.ipv6_src
);
423 if (!flow
->tunnel
.ip_src
) {
424 flow
->tunnel
.ipv6_src
= tnl_port
->match
.ipv6_src
;
426 flow
->tunnel
.ipv6_src
= in6addr_any
;
429 if (!cfg
->ip_dst_flow
) {
430 flow
->tunnel
.ip_dst
= in6_addr_get_mapped_ipv4(&tnl_port
->match
.ipv6_dst
);
431 if (!flow
->tunnel
.ip_dst
) {
432 flow
->tunnel
.ipv6_dst
= tnl_port
->match
.ipv6_dst
;
434 flow
->tunnel
.ipv6_dst
= in6addr_any
;
437 flow
->tunnel
.tp_dst
= cfg
->dst_port
;
438 if (!cfg
->out_key_flow
) {
439 flow
->tunnel
.tun_id
= cfg
->out_key
;
442 if (cfg
->ttl_inherit
&& is_ip_any(flow
)) {
443 wc
->masks
.nw_ttl
= 0xff;
444 flow
->tunnel
.ip_ttl
= flow
->nw_ttl
;
446 flow
->tunnel
.ip_ttl
= cfg
->ttl
;
449 if (cfg
->tos_inherit
&& is_ip_any(flow
)) {
450 wc
->masks
.nw_tos
|= IP_DSCP_MASK
;
451 flow
->tunnel
.ip_tos
= flow
->nw_tos
& IP_DSCP_MASK
;
453 flow
->tunnel
.ip_tos
= cfg
->tos
;
456 /* ECN fields are always inherited. */
457 if (is_ip_any(flow
)) {
458 wc
->masks
.nw_tos
|= IP_ECN_MASK
;
460 if (IP_ECN_is_ce(flow
->nw_tos
)) {
461 flow
->tunnel
.ip_tos
|= IP_ECN_ECT_0
;
463 flow
->tunnel
.ip_tos
|= flow
->nw_tos
& IP_ECN_MASK
;
467 flow
->tunnel
.flags
&= ~(FLOW_TNL_F_MASK
& ~FLOW_TNL_PUB_F_MASK
);
468 flow
->tunnel
.flags
|= (cfg
->dont_fragment
? FLOW_TNL_F_DONT_FRAGMENT
: 0)
469 | (cfg
->csum
? FLOW_TNL_F_CSUM
: 0)
470 | (cfg
->out_key_present
? FLOW_TNL_F_KEY
: 0);
472 if (cfg
->set_egress_pkt_mark
) {
473 flow
->pkt_mark
= cfg
->egress_pkt_mark
;
474 wc
->masks
.pkt_mark
= UINT32_MAX
;
478 char *post_flow_str
= flow_to_string(flow
, NULL
);
479 char *tnl_str
= tnl_port_to_string(tnl_port
);
480 VLOG_DBG("flow sent\n"
484 tnl_str
, pre_flow_str
, post_flow_str
);
491 fat_rwlock_unlock(&rwlock
);
496 tnl_hash(struct tnl_match
*match
)
498 BUILD_ASSERT_DECL(sizeof *match
% sizeof(uint32_t) == 0);
499 return hash_words((uint32_t *) match
, sizeof *match
/ sizeof(uint32_t), 0);
502 static struct tnl_port
*
503 tnl_find_ofport(const struct ofport_dpif
*ofport
) OVS_REQ_RDLOCK(rwlock
)
505 struct tnl_port
*tnl_port
;
507 HMAP_FOR_EACH_IN_BUCKET (tnl_port
, ofport_node
, hash_pointer(ofport
, 0),
509 if (tnl_port
->ofport
== ofport
) {
516 static struct tnl_port
*
517 tnl_find_exact(struct tnl_match
*match
, struct hmap
*map
)
518 OVS_REQ_RDLOCK(rwlock
)
521 struct tnl_port
*tnl_port
;
523 HMAP_FOR_EACH_WITH_HASH (tnl_port
, match_node
, tnl_hash(match
), map
) {
524 if (!memcmp(match
, &tnl_port
->match
, sizeof *match
)) {
532 /* Returns the tnl_port that is the best match for the tunnel data in 'flow',
533 * or NULL if no tnl_port matches 'flow'. */
534 static struct tnl_port
*
535 tnl_find(const struct flow
*flow
) OVS_REQ_RDLOCK(rwlock
)
537 enum ip_src_type ip_src
;
543 for (in_key_flow
= 0; in_key_flow
< 2; in_key_flow
++) {
544 for (ip_dst_flow
= 0; ip_dst_flow
< 2; ip_dst_flow
++) {
545 for (ip_src
= 0; ip_src
< 3; ip_src
++) {
546 struct hmap
*map
= tnl_match_maps
[i
];
549 struct tnl_port
*tnl_port
;
550 struct tnl_match match
;
552 memset(&match
, 0, sizeof match
);
554 /* The apparent mix-up of 'ip_dst' and 'ip_src' below is
555 * correct, because "struct tnl_match" is expressed in
556 * terms of packets being sent out, but we are using it
557 * here as a description of how to treat received
559 match
.in_key
= in_key_flow
? 0 : flow
->tunnel
.tun_id
;
560 if (ip_src
== IP_SRC_CFG
) {
561 match
.ipv6_src
= flow_tnl_dst(&flow
->tunnel
);
564 match
.ipv6_dst
= flow_tnl_src(&flow
->tunnel
);
566 match
.odp_port
= flow
->in_port
.odp_port
;
567 match
.in_key_flow
= in_key_flow
;
568 match
.ip_dst_flow
= ip_dst_flow
;
569 match
.ip_src_flow
= ip_src
== IP_SRC_FLOW
;
571 /* Look for a legacy L2 or L3 tunnel port first. */
572 if (pt_ns(flow
->packet_type
) == OFPHTN_ETHERTYPE
) {
573 match
.pt_mode
= NETDEV_PT_LEGACY_L3
;
575 match
.pt_mode
= NETDEV_PT_LEGACY_L2
;
577 tnl_port
= tnl_find_exact(&match
, map
);
582 /* Then check for a packet type aware port. */
583 match
.pt_mode
= NETDEV_PT_AWARE
;
584 tnl_port
= tnl_find_exact(&match
, map
);
598 /* Returns a pointer to the 'tnl_match_maps' element corresponding to 'm''s
599 * matching criteria. */
600 static struct hmap
**
601 tnl_match_map(const struct tnl_match
*m
)
603 enum ip_src_type ip_src
;
605 ip_src
= (m
->ip_src_flow
? IP_SRC_FLOW
606 : ipv6_addr_is_set(&m
->ipv6_src
) ? IP_SRC_CFG
609 return &tnl_match_maps
[6 * m
->in_key_flow
+ 3 * m
->ip_dst_flow
+ ip_src
];
613 tnl_match_fmt(const struct tnl_match
*match
, struct ds
*ds
)
614 OVS_REQ_RDLOCK(rwlock
)
616 if (!match
->ip_dst_flow
) {
617 ipv6_format_mapped(&match
->ipv6_src
, ds
);
618 ds_put_cstr(ds
, "->");
619 ipv6_format_mapped(&match
->ipv6_dst
, ds
);
620 } else if (!match
->ip_src_flow
) {
621 ipv6_format_mapped(&match
->ipv6_src
, ds
);
622 ds_put_cstr(ds
, "->flow");
624 ds_put_cstr(ds
, "flow->flow");
627 if (match
->in_key_flow
) {
628 ds_put_cstr(ds
, ", key=flow");
630 ds_put_format(ds
, ", key=%#"PRIx64
, ntohll(match
->in_key
));
634 = (match
->pt_mode
== NETDEV_PT_LEGACY_L2
? "legacy_l2"
635 : match
->pt_mode
== NETDEV_PT_LEGACY_L3
? "legacy_l3"
637 ds_put_format(ds
, ", %s, dp port=%"PRIu32
, pt_mode
, match
->odp_port
);
641 tnl_port_mod_log(const struct tnl_port
*tnl_port
, const char *action
)
642 OVS_REQ_RDLOCK(rwlock
)
644 if (VLOG_IS_DBG_ENABLED()) {
645 struct ds ds
= DS_EMPTY_INITIALIZER
;
647 tnl_match_fmt(&tnl_port
->match
, &ds
);
648 VLOG_INFO("%s tunnel port %s (%s)", action
,
649 tnl_port_get_name(tnl_port
), ds_cstr(&ds
));
654 static void OVS_REQ_RDLOCK(rwlock
)
655 tnl_port_format(const struct tnl_port
*tnl_port
, struct ds
*ds
)
657 const struct netdev_tunnel_config
*cfg
=
658 netdev_get_tunnel_config(tnl_port
->netdev
);
660 ds_put_format(ds
, "port %"PRIu32
": %s (%s: ", tnl_port
->match
.odp_port
,
661 tnl_port_get_name(tnl_port
),
662 netdev_get_type(tnl_port
->netdev
));
663 tnl_match_fmt(&tnl_port
->match
, ds
);
665 if (cfg
->out_key
!= cfg
->in_key
||
666 cfg
->out_key_present
!= cfg
->in_key_present
||
667 cfg
->out_key_flow
!= cfg
->in_key_flow
) {
668 ds_put_cstr(ds
, ", out_key=");
669 if (!cfg
->out_key_present
) {
670 ds_put_cstr(ds
, "none");
671 } else if (cfg
->out_key_flow
) {
672 ds_put_cstr(ds
, "flow");
674 ds_put_format(ds
, "%#"PRIx64
, ntohll(cfg
->out_key
));
678 if (cfg
->ttl_inherit
) {
679 ds_put_cstr(ds
, ", ttl=inherit");
681 ds_put_format(ds
, ", ttl=%"PRIu8
, cfg
->ttl
);
684 if (cfg
->tos_inherit
) {
685 ds_put_cstr(ds
, ", tos=inherit");
686 } else if (cfg
->tos
) {
687 ds_put_format(ds
, ", tos=%#"PRIx8
, cfg
->tos
);
690 if (!cfg
->dont_fragment
) {
691 ds_put_cstr(ds
, ", df=false");
695 ds_put_cstr(ds
, ", csum=true");
698 ds_put_cstr(ds
, ")\n");
701 static char * OVS_REQ_RDLOCK(rwlock
)
702 tnl_port_to_string(const struct tnl_port
*tnl_port
)
704 struct ds ds
= DS_EMPTY_INITIALIZER
;
705 tnl_port_format(tnl_port
, &ds
);
706 return ds_steal_cstr(&ds
);
710 tnl_port_get_name(const struct tnl_port
*tnl_port
) OVS_REQ_RDLOCK(rwlock
)
712 return netdev_get_name(tnl_port
->netdev
);
716 tnl_port_build_header(const struct ofport_dpif
*ofport
,
717 struct ovs_action_push_tnl
*data
,
718 const struct netdev_tnl_build_header_params
*params
)
720 struct tnl_port
*tnl_port
;
723 fat_rwlock_rdlock(&rwlock
);
724 tnl_port
= tnl_find_ofport(ofport
);
725 ovs_assert(tnl_port
);
726 res
= netdev_build_header(tnl_port
->netdev
, data
, params
);
727 fat_rwlock_unlock(&rwlock
);
733 tnl_unixctl_list(struct unixctl_conn
*conn
,
734 int argc OVS_UNUSED
, const char *argv
[] OVS_UNUSED
,
735 void *aux OVS_UNUSED
)
737 struct ds reply
= DS_EMPTY_INITIALIZER
;
739 fat_rwlock_rdlock(&rwlock
);
740 for (int i
= 0; i
< N_MATCH_TYPES
; i
++) {
741 struct hmap
*map
= tnl_match_maps
[i
];
743 struct tnl_port
*tnl_port
;
744 HMAP_FOR_EACH (tnl_port
, match_node
, map
) {
745 tnl_port_format(tnl_port
, &reply
);
749 fat_rwlock_unlock(&rwlock
);
751 unixctl_command_reply(conn
, ds_cstr(&reply
));