From: Ansis Atteka Date: Mon, 19 Dec 2011 20:43:34 +0000 (-0800) Subject: vswitchd: In-band rules for Controller are missing after executing force-reload-kmod... X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ac4c900d4b88848cd350fc82665de51ac1497668;p=openvswitch vswitchd: In-band rules for Controller are missing after executing force-reload-kmod command In current implementation vswitchd adds Controller in-band rules only if there is a route in kernel routing table that might route traffic to the Controller. But, when executing force-reload-kmod command, network configuration (e.g. assigned IP addresses, routes) are flushed away, hence Controller in-band rules are not added. This commit fixes this limitation and allows vswitchd to add Controller in-band rules even if there are no routes in the kernel routing table. Issue: #8625 Signed-off-by: Ansis Atteka --- diff --git a/lib/stream.c b/lib/stream.c index 9ba4c518..4c3583c4 100644 --- a/lib/stream.c +++ b/lib/stream.c @@ -724,7 +724,27 @@ pstream_open_with_default_ports(const char *name_, return error; } - + +/* + * This function extracts IP address and port from the target string. + * + * - On success, function returns true and fills *sin structure with port + * and IP address. If port was absent in target string then it will use + * corresponding default port value. + * - On error, function returns false and *sin contains garbage. + */ +bool +stream_parse_target_with_default_ports(const char *target, + uint16_t default_tcp_port, + uint16_t default_ssl_port, + struct sockaddr_in *sin) +{ + return (!strncmp(target, "tcp:", 4) + && inet_parse_active(target + 4, default_tcp_port, sin)) || + (!strncmp(target, "ssl:", 4) + && inet_parse_active(target + 4, default_ssl_port, sin)); +} + /* Attempts to guess the content type of a stream whose first few bytes were * the 'size' bytes of 'data'. */ static enum stream_content_type diff --git a/lib/stream.h b/lib/stream.h index 51a76566..5c111f99 100644 --- a/lib/stream.h +++ b/lib/stream.h @@ -23,6 +23,7 @@ #include #include "openvswitch/types.h" #include "vlog.h" +#include "socket-util.h" struct pstream; struct stream; @@ -75,7 +76,11 @@ int pstream_open_with_default_ports(const char *name, uint16_t default_ptcp_port, uint16_t default_pssl_port, struct pstream **); - +bool stream_parse_target_with_default_ports(const char *target, + uint16_t default_tcp_port, + uint16_t default_ssl_port, + struct sockaddr_in *sin); + /* Error reporting. */ enum stream_content_type { diff --git a/ofproto/connmgr.c b/ofproto/connmgr.c index 6432ba66..1c55b677 100644 --- a/ofproto/connmgr.c +++ b/ofproto/connmgr.c @@ -587,14 +587,16 @@ update_in_band_remotes(struct connmgr *mgr) /* Add all the remotes. */ HMAP_FOR_EACH (ofconn, hmap_node, &mgr->controllers) { struct sockaddr_in *sin = &addrs[n_addrs]; + const char *target = rconn_get_target(ofconn->rconn); if (ofconn->band == OFPROTO_OUT_OF_BAND) { continue; } - sin->sin_addr.s_addr = rconn_get_remote_ip(ofconn->rconn); - if (sin->sin_addr.s_addr) { - sin->sin_port = rconn_get_remote_port(ofconn->rconn); + if (stream_parse_target_with_default_ports(target, + OFP_TCP_PORT, + OFP_SSL_PORT, + sin)) { n_addrs++; } } diff --git a/vswitchd/bridge.c b/vswitchd/bridge.c index 396c7206..3ae3b0f8 100644 --- a/vswitchd/bridge.c +++ b/vswitchd/bridge.c @@ -373,10 +373,10 @@ collect_in_band_managers(const struct ovsrec_open_vswitch *ovs_cfg, SSET_FOR_EACH (target, &targets) { struct sockaddr_in *sin = &managers[n_managers]; - if ((!strncmp(target, "tcp:", 4) - && inet_parse_active(target + 4, JSONRPC_TCP_PORT, sin)) || - (!strncmp(target, "ssl:", 4) - && inet_parse_active(target + 4, JSONRPC_SSL_PORT, sin))) { + if (stream_parse_target_with_default_ports(target, + JSONRPC_TCP_PORT, + JSONRPC_SSL_PORT, + sin)) { n_managers++; } }