1 /* Copyright (c) 2008, 2009 Nicira Networks
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.
18 #include <asm/param.h>
25 #include <linux/genetlink.h>
26 #include <linux/rtnetlink.h>
30 #include <sys/types.h>
37 #include "command-line.h"
42 #include "dynamic-string.h"
43 #include "fatal-signal.h"
45 #include "leak-checker.h"
49 #include "openvswitch/brcompat-netlink.h"
51 #include "poll-loop.h"
60 #define THIS_MODULE VLM_brcompatd
63 /* xxx Just hangs if datapath is rmmod/insmod. Learn to reconnect? */
65 /* Actions to modify bridge compatibility configuration. */
73 static void parse_options(int argc
, char *argv
[]);
74 static void usage(void) NO_RETURN
;
76 static struct vlog_rate_limit rl
= VLOG_RATE_LIMIT_INIT(5, 60);
78 /* Maximum number of milliseconds to wait for the config file to be
79 * unlocked. If set to zero, no waiting will occur. */
80 static int lock_timeout
= 500;
82 /* Maximum number of milliseconds to wait before pruning port entries that
83 * no longer exist. If set to zero, ports are never pruned. */
84 static int prune_timeout
= 5000;
86 /* Config file shared with ovs-vswitchd (usually ovs-vswitchd.conf). */
87 static char *config_file
;
89 /* Shell command to execute (via popen()) to send a control command to the
90 * running ovs-vswitchd process. The string must contain one instance of %s,
91 * which is replaced by the control command. */
92 static char *appctl_command
;
94 /* Netlink socket to listen for interface changes. */
95 static struct nl_sock
*rtnl_sock
;
97 /* Netlink socket to bridge compatibility kernel module. */
98 static struct nl_sock
*brc_sock
;
100 /* The Generic Netlink family number used for bridge compatibility. */
101 static int brc_family
;
103 static const struct nl_policy brc_multicast_policy
[] = {
104 [BRC_GENL_A_MC_GROUP
] = {.type
= NL_A_U32
}
107 static const struct nl_policy rtnlgrp_link_policy
[] = {
108 [IFLA_IFNAME
] = { .type
= NL_A_STRING
, .optional
= false },
109 [IFLA_MASTER
] = { .type
= NL_A_U32
, .optional
= true },
113 lookup_brc_multicast_group(int *multicast_group
)
115 struct nl_sock
*sock
;
116 struct ofpbuf request
, *reply
;
117 struct nlattr
*attrs
[ARRAY_SIZE(brc_multicast_policy
)];
120 retval
= nl_sock_create(NETLINK_GENERIC
, 0, 0, 0, &sock
);
124 ofpbuf_init(&request
, 0);
125 nl_msg_put_genlmsghdr(&request
, sock
, 0, brc_family
,
126 NLM_F_REQUEST
, BRC_GENL_C_QUERY_MC
, 1);
127 retval
= nl_sock_transact(sock
, &request
, &reply
);
128 ofpbuf_uninit(&request
);
130 nl_sock_destroy(sock
);
133 if (!nl_policy_parse(reply
, NLMSG_HDRLEN
+ GENL_HDRLEN
,
134 brc_multicast_policy
, attrs
,
135 ARRAY_SIZE(brc_multicast_policy
))) {
136 nl_sock_destroy(sock
);
137 ofpbuf_delete(reply
);
140 *multicast_group
= nl_attr_get_u32(attrs
[BRC_GENL_A_MC_GROUP
]);
141 nl_sock_destroy(sock
);
142 ofpbuf_delete(reply
);
147 /* Opens a socket for brcompat notifications. Returns 0 if successful,
148 * otherwise a positive errno value. */
150 brc_open(struct nl_sock
**sock
)
152 int multicast_group
= 0;
155 retval
= nl_lookup_genl_family(BRC_GENL_FAMILY_NAME
, &brc_family
);
160 retval
= lookup_brc_multicast_group(&multicast_group
);
165 retval
= nl_sock_create(NETLINK_GENERIC
, multicast_group
, 0, 0, sock
);
173 static const struct nl_policy brc_dp_policy
[] = {
174 [BRC_GENL_A_DP_NAME
] = { .type
= NL_A_STRING
},
178 bridge_exists(const char *name
)
180 return cfg_has_section("bridge.%s", name
);
184 execute_appctl_command(const char *unixctl_command
, char **output
)
186 char *stdout_log
, *stderr_log
;
192 argv
[2] = xasprintf(appctl_command
, unixctl_command
);
195 /* Run process and log status. */
196 error
= process_run_capture(argv
, &stdout_log
, &stderr_log
, &status
);
198 VLOG_ERR("failed to execute %s command via ovs-appctl: %s",
199 unixctl_command
, strerror(error
));
201 char *msg
= process_status_msg(status
);
202 VLOG_ERR("ovs-appctl exited with error (%s)", msg
);
207 /* Deal with stdout_log. */
209 *output
= stdout_log
;
214 /* Deal with stderr_log */
215 if (stderr_log
&& *stderr_log
) {
216 VLOG_INFO("ovs-appctl wrote to stderr:\n%s", stderr_log
);
226 rewrite_and_reload_config(void)
228 if (cfg_is_dirty()) {
229 int error1
= cfg_write();
230 int error2
= cfg_read();
231 long long int reload_start
= time_msec();
232 int error3
= execute_appctl_command("vswitchd/reload", NULL
);
233 long long int elapsed
= time_msec() - reload_start
;
234 COVERAGE_INC(brcompatd_reload
);
236 VLOG_INFO("reload command executed in %lld ms", elapsed
);
238 return error1
? error1
: error2
? error2
: error3
;
243 /* Get all the interfaces for 'bridge' as 'ifaces', breaking bonded interfaces
244 * down into their constituent parts.
246 * If 'vlan' < 0, all interfaces on 'bridge' are reported. If 'vlan' == 0,
247 * then only interfaces for trunk ports or ports with implicit VLAN 0 are
248 * reported. If 'vlan' > 0, only interfaces with implict VLAN 'vlan' are
251 get_bridge_ifaces(const char *bridge
, struct svec
*ifaces
, int vlan
)
258 cfg_get_all_keys(&ports
, "bridge.%s.port", bridge
);
259 for (i
= 0; i
< ports
.n
; i
++) {
260 const char *port_name
= ports
.names
[i
];
262 int port_vlan
= cfg_get_vlan(0, "vlan.%s.tag", port_name
);
266 if (vlan
!= port_vlan
) {
270 if (cfg_has_section("bonding.%s", port_name
)) {
273 cfg_get_all_keys(&slaves
, "bonding.%s.slave", port_name
);
274 svec_append(ifaces
, &slaves
);
275 svec_destroy(&slaves
);
277 svec_add(ifaces
, port_name
);
280 svec_destroy(&ports
);
283 /* Go through the configuration file and remove any ports that no longer
284 * exist associated with a bridge. */
290 struct svec bridges
, delete;
292 if (cfg_lock(NULL
, 0)) {
293 /* Couldn't lock config file. */
299 cfg_get_subsections(&bridges
, "bridge");
300 for (i
=0; i
<bridges
.n
; i
++) {
301 const char *br_name
= bridges
.names
[i
];
304 /* Check that each bridge interface exists. */
305 get_bridge_ifaces(br_name
, &ifaces
, -1);
306 for (j
= 0; j
< ifaces
.n
; j
++) {
307 const char *iface_name
= ifaces
.names
[j
];
308 enum netdev_flags flags
;
310 /* The local port and internal ports are created and destroyed by
311 * ovs-vswitchd itself, so don't bother checking for them at all.
312 * In practice, they might not exist if ovs-vswitchd hasn't
313 * finished reloading since the configuration file was updated. */
314 if (!strcmp(iface_name
, br_name
)
315 || cfg_get_bool(0, "iface.%s.internal", iface_name
)) {
319 error
= netdev_nodev_get_flags(iface_name
, &flags
);
320 if (error
== ENODEV
) {
321 VLOG_INFO_RL(&rl
, "removing dead interface %s from %s",
322 iface_name
, br_name
);
323 svec_add(&delete, iface_name
);
325 VLOG_INFO_RL(&rl
, "unknown error %d on interface %s from %s",
326 error
, iface_name
, br_name
);
329 svec_destroy(&ifaces
);
331 svec_destroy(&bridges
);
336 for (i
= 0; i
< delete.n
; i
++) {
337 cfg_del_match("bridge.*.port=%s", delete.names
[i
]);
338 cfg_del_match("bonding.*.slave=%s", delete.names
[i
]);
340 rewrite_and_reload_config();
345 svec_destroy(&delete);
349 /* Checks whether a network device named 'name' exists and returns true if so,
352 * XXX it is possible that this doesn't entirely accomplish what we want in
353 * context, since ovs-vswitchd.conf may cause vswitchd to create or destroy
354 * network devices based on iface.*.internal settings.
356 * XXX may want to move this to lib/netdev.
358 * XXX why not just use netdev_nodev_get_flags() or similar function? */
360 netdev_exists(const char *name
)
366 filename
= xasprintf("/sys/class/net/%s", name
);
367 error
= stat(filename
, &s
);
373 add_bridge(const char *br_name
)
375 if (bridge_exists(br_name
)) {
376 VLOG_WARN("addbr %s: bridge %s exists", br_name
, br_name
);
378 } else if (netdev_exists(br_name
)) {
379 if (cfg_get_bool(0, "iface.%s.fake-bridge", br_name
)) {
380 VLOG_WARN("addbr %s: %s exists as a fake bridge",
384 VLOG_WARN("addbr %s: cannot create bridge %s because a network "
385 "device named %s already exists",
386 br_name
, br_name
, br_name
);
391 cfg_add_entry("bridge.%s.port=%s", br_name
, br_name
);
392 VLOG_INFO("addbr %s: success", br_name
);
398 del_bridge(const char *br_name
)
400 if (!bridge_exists(br_name
)) {
401 VLOG_WARN("delbr %s: no bridge named %s", br_name
, br_name
);
405 cfg_del_section("bridge.%s", br_name
);
406 VLOG_INFO("delbr %s: success", br_name
);
412 parse_command(struct ofpbuf
*buffer
, uint32_t *seq
, const char **br_name
,
413 const char **port_name
, uint64_t *count
, uint64_t *skip
)
415 static const struct nl_policy policy
[] = {
416 [BRC_GENL_A_DP_NAME
] = { .type
= NL_A_STRING
, .optional
= true },
417 [BRC_GENL_A_PORT_NAME
] = { .type
= NL_A_STRING
, .optional
= true },
418 [BRC_GENL_A_FDB_COUNT
] = { .type
= NL_A_U64
, .optional
= true },
419 [BRC_GENL_A_FDB_SKIP
] = { .type
= NL_A_U64
, .optional
= true },
421 struct nlattr
*attrs
[ARRAY_SIZE(policy
)];
423 if (!nl_policy_parse(buffer
, NLMSG_HDRLEN
+ GENL_HDRLEN
, policy
,
424 attrs
, ARRAY_SIZE(policy
))
425 || (br_name
&& !attrs
[BRC_GENL_A_DP_NAME
])
426 || (port_name
&& !attrs
[BRC_GENL_A_PORT_NAME
])
427 || (count
&& !attrs
[BRC_GENL_A_FDB_COUNT
])
428 || (skip
&& !attrs
[BRC_GENL_A_FDB_SKIP
])) {
432 *seq
= ((struct nlmsghdr
*) buffer
->data
)->nlmsg_seq
;
434 *br_name
= nl_attr_get_string(attrs
[BRC_GENL_A_DP_NAME
]);
437 *port_name
= nl_attr_get_string(attrs
[BRC_GENL_A_PORT_NAME
]);
440 *count
= nl_attr_get_u64(attrs
[BRC_GENL_A_FDB_COUNT
]);
443 *skip
= nl_attr_get_u64(attrs
[BRC_GENL_A_FDB_SKIP
]);
449 send_reply(uint32_t seq
, int error
, struct ofpbuf
*fdb_query_data
)
455 ofpbuf_init(&msg
, 0);
456 nl_msg_put_genlmsghdr(&msg
, brc_sock
, 32, brc_family
, NLM_F_REQUEST
,
457 BRC_GENL_C_DP_RESULT
, 1);
458 ((struct nlmsghdr
*) msg
.data
)->nlmsg_seq
= seq
;
459 nl_msg_put_u32(&msg
, BRC_GENL_A_ERR_CODE
, error
);
460 if (fdb_query_data
) {
461 nl_msg_put_unspec(&msg
, BRC_GENL_A_FDB_DATA
,
462 fdb_query_data
->data
, fdb_query_data
->size
);
466 retval
= nl_sock_send(brc_sock
, &msg
, false);
468 VLOG_WARN_RL(&rl
, "replying to brcompat request: %s",
475 handle_bridge_cmd(struct ofpbuf
*buffer
, bool add
)
481 error
= parse_command(buffer
, &seq
, &br_name
, NULL
, NULL
, NULL
);
483 error
= add
? add_bridge(br_name
) : del_bridge(br_name
);
485 error
= rewrite_and_reload_config();
487 send_reply(seq
, error
, NULL
);
492 static const struct nl_policy brc_port_policy
[] = {
493 [BRC_GENL_A_DP_NAME
] = { .type
= NL_A_STRING
},
494 [BRC_GENL_A_PORT_NAME
] = { .type
= NL_A_STRING
},
498 del_port(const char *br_name
, const char *port_name
)
500 cfg_del_entry("bridge.%s.port=%s", br_name
, port_name
);
501 cfg_del_match("bonding.*.slave=%s", port_name
);
502 cfg_del_match("vlan.%s.*", port_name
);
506 handle_port_cmd(struct ofpbuf
*buffer
, bool add
)
508 const char *cmd_name
= add
? "add-if" : "del-if";
509 const char *br_name
, *port_name
;
513 error
= parse_command(buffer
, &seq
, &br_name
, &port_name
, NULL
, NULL
);
515 if (!bridge_exists(br_name
)) {
516 VLOG_WARN("%s %s %s: no bridge named %s",
517 cmd_name
, br_name
, port_name
, br_name
);
519 } else if (!netdev_exists(port_name
)) {
520 VLOG_WARN("%s %s %s: no network device named %s",
521 cmd_name
, br_name
, port_name
, port_name
);
525 cfg_add_entry("bridge.%s.port=%s", br_name
, port_name
);
527 del_port(br_name
, port_name
);
529 VLOG_INFO("%s %s %s: success", cmd_name
, br_name
, port_name
);
530 error
= rewrite_and_reload_config();
532 send_reply(seq
, error
, NULL
);
538 /* Returns the name of the bridge that contains a port named 'port_name', as a
539 * malloc'd string that the caller must free, or a null pointer if no bridge
540 * contains a port named 'port_name'. */
542 get_bridge_containing_port(const char *port_name
)
545 const char *start
, *end
;
548 cfg_get_matches(&matches
, "bridge.*.port=%s", port_name
);
553 start
= matches
.names
[0] + strlen("bridge.");
554 end
= strstr(start
, ".port=");
556 return xmemdup0(start
, end
- start
);
560 handle_fdb_query_cmd(struct ofpbuf
*buffer
)
562 /* This structure is copied directly from the Linux 2.6.30 header files.
563 * It would be more straightforward to #include <linux/if_bridge.h>, but
564 * the 'port_hi' member was only introduced in Linux 2.6.26 and so systems
565 * with old header files won't have it. */
570 __u32 ageing_timer_value
;
579 struct mac
*local_macs
;
583 /* Impedance matching between the vswitchd and Linux kernel notions of what
584 * a bridge is. The kernel only handles a single VLAN per bridge, but
585 * vswitchd can deal with all the VLANs on a single bridge. We have to
586 * pretend that the former is the case even though the latter is the
588 const char *linux_bridge
; /* Name used by brctl. */
589 char *ovs_bridge
; /* Name used by ovs-vswitchd. */
590 int br_vlan
; /* VLAN tag. */
593 struct ofpbuf query_data
;
594 char *unixctl_command
;
595 uint64_t count
, skip
;
601 /* Parse the command received from brcompat_mod. */
602 error
= parse_command(buffer
, &seq
, &linux_bridge
, NULL
, &count
, &skip
);
607 /* Figure out vswitchd bridge and VLAN. */
609 if (bridge_exists(linux_bridge
)) {
610 /* Bridge name is the same. We are interested in VLAN 0. */
611 ovs_bridge
= xstrdup(linux_bridge
);
614 /* No such Open vSwitch bridge 'linux_bridge', but there might be an
615 * internal port named 'linux_bridge' on some other bridge
616 * 'ovs_bridge'. If so then we are interested in the VLAN assigned to
617 * port 'linux_bridge' on the bridge named 'ovs_bridge'. */
618 const char *port_name
= linux_bridge
;
620 ovs_bridge
= get_bridge_containing_port(port_name
);
621 br_vlan
= cfg_get_vlan(0, "vlan.%s.tag", port_name
);
622 if (!ovs_bridge
|| br_vlan
< 0) {
624 send_reply(seq
, ENODEV
, NULL
);
629 /* Fetch the forwarding database using ovs-appctl. */
630 unixctl_command
= xasprintf("fdb/show %s", ovs_bridge
);
631 error
= execute_appctl_command(unixctl_command
, &output
);
632 free(unixctl_command
);
635 send_reply(seq
, error
, NULL
);
639 /* Fetch the MAC address for each interface on the bridge, so that we can
640 * fill in the is_local field in the response. */
641 get_bridge_ifaces(ovs_bridge
, &ifaces
, br_vlan
);
642 local_macs
= xmalloc(ifaces
.n
* sizeof *local_macs
);
644 for (i
= 0; i
< ifaces
.n
; i
++) {
645 const char *iface_name
= ifaces
.names
[i
];
646 struct mac
*mac
= &local_macs
[n_local_macs
];
647 if (!netdev_nodev_get_etheraddr(iface_name
, mac
->addr
)) {
651 svec_destroy(&ifaces
);
653 /* Parse the response from ovs-appctl and convert it to binary format to
654 * pass back to the kernel. */
655 ofpbuf_init(&query_data
, sizeof(struct __fdb_entry
) * 8);
657 strtok_r(output
, "\n", &save_ptr
); /* Skip header line. */
659 struct __fdb_entry
*entry
;
661 uint8_t mac
[ETH_ADDR_LEN
];
665 line
= strtok_r(NULL
, "\n", &save_ptr
);
670 if (sscanf(line
, "%d %d "ETH_ADDR_SCAN_FMT
" %d",
671 &port
, &vlan
, ETH_ADDR_SCAN_ARGS(mac
), &age
)
672 != 2 + ETH_ADDR_SCAN_COUNT
+ 1) {
673 struct vlog_rate_limit rl
= VLOG_RATE_LIMIT_INIT(1, 1);
674 VLOG_INFO_RL(&rl
, "fdb/show output has invalid format: %s", line
);
678 if (vlan
!= br_vlan
) {
687 /* Is this the MAC address of an interface on the bridge? */
689 for (i
= 0; i
< n_local_macs
; i
++) {
690 if (eth_addr_equals(local_macs
[i
].addr
, mac
)) {
696 entry
= ofpbuf_put_uninit(&query_data
, sizeof *entry
);
697 memcpy(entry
->mac_addr
, mac
, ETH_ADDR_LEN
);
698 entry
->port_no
= port
& 0xff;
699 entry
->is_local
= is_local
;
700 entry
->ageing_timer_value
= age
* HZ
;
701 entry
->port_hi
= (port
& 0xff00) >> 8;
708 send_reply(seq
, 0, &query_data
);
709 ofpbuf_uninit(&query_data
);
716 brc_recv_update(void)
719 struct ofpbuf
*buffer
;
720 struct genlmsghdr
*genlmsghdr
;
725 ofpbuf_delete(buffer
);
726 retval
= nl_sock_recv(brc_sock
, &buffer
, false);
727 } while (retval
== ENOBUFS
729 && (nl_msg_nlmsgerr(buffer
, NULL
)
730 || nl_msg_nlmsghdr(buffer
)->nlmsg_type
== NLMSG_DONE
)));
732 if (retval
!= EAGAIN
) {
733 VLOG_WARN_RL(&rl
, "brc_recv_update: %s", strerror(retval
));
738 genlmsghdr
= nl_msg_genlmsghdr(buffer
);
740 VLOG_WARN_RL(&rl
, "received packet too short for generic NetLink");
744 if (nl_msg_nlmsghdr(buffer
)->nlmsg_type
!= brc_family
) {
745 VLOG_DBG_RL(&rl
, "received type (%"PRIu16
") != brcompat family (%d)",
746 nl_msg_nlmsghdr(buffer
)->nlmsg_type
, brc_family
);
750 if (cfg_lock(NULL
, lock_timeout
)) {
751 /* Couldn't lock config file. */
756 switch (genlmsghdr
->cmd
) {
757 case BRC_GENL_C_DP_ADD
:
758 retval
= handle_bridge_cmd(buffer
, true);
761 case BRC_GENL_C_DP_DEL
:
762 retval
= handle_bridge_cmd(buffer
, false);
765 case BRC_GENL_C_PORT_ADD
:
766 retval
= handle_port_cmd(buffer
, true);
769 case BRC_GENL_C_PORT_DEL
:
770 retval
= handle_port_cmd(buffer
, false);
773 case BRC_GENL_C_FDB_QUERY
:
774 retval
= handle_fdb_query_cmd(buffer
);
784 ofpbuf_delete(buffer
);
788 /* Check for interface configuration changes announced through RTNL. */
790 rtnl_recv_update(void)
794 int error
= nl_sock_recv(rtnl_sock
, &buf
, false);
795 if (error
== EAGAIN
) {
797 } else if (error
== ENOBUFS
) {
798 VLOG_WARN_RL(&rl
, "network monitor socket overflowed");
800 VLOG_WARN_RL(&rl
, "error on network monitor socket: %s",
803 struct nlattr
*attrs
[ARRAY_SIZE(rtnlgrp_link_policy
)];
804 struct nlmsghdr
*nlh
;
805 struct ifinfomsg
*iim
;
807 nlh
= ofpbuf_at(buf
, 0, NLMSG_HDRLEN
);
808 iim
= ofpbuf_at(buf
, NLMSG_HDRLEN
, sizeof *iim
);
810 VLOG_WARN_RL(&rl
, "received bad rtnl message (no ifinfomsg)");
815 if (!nl_policy_parse(buf
, NLMSG_HDRLEN
+ sizeof(struct ifinfomsg
),
817 attrs
, ARRAY_SIZE(rtnlgrp_link_policy
))) {
818 VLOG_WARN_RL(&rl
,"received bad rtnl message (policy)");
822 if (nlh
->nlmsg_type
== RTM_DELLINK
&& attrs
[IFLA_MASTER
]) {
823 const char *port_name
= nl_attr_get_string(attrs
[IFLA_IFNAME
]);
824 char br_name
[IFNAMSIZ
];
825 uint32_t br_idx
= nl_attr_get_u32(attrs
[IFLA_MASTER
]);
827 enum netdev_flags flags
;
829 if (!if_indextoname(br_idx
, br_name
)) {
834 if (cfg_lock(NULL
, lock_timeout
)) {
835 /* Couldn't lock config file. */
836 /* xxx this should try again and print error msg. */
841 if (netdev_nodev_get_flags(port_name
, &flags
) == ENODEV
) {
842 /* Network device is really gone. */
843 VLOG_INFO("network device %s destroyed, "
844 "removing from bridge %s", port_name
, br_name
);
846 cfg_get_all_keys(&ports
, "bridge.%s.port", br_name
);
848 if (svec_contains(&ports
, port_name
)) {
849 del_port(br_name
, port_name
);
850 rewrite_and_reload_config();
853 /* A network device by that name exists even though the kernel
854 * told us it had disappeared. Probably, what happened was
857 * 1. Device destroyed.
858 * 2. Notification sent to us.
859 * 3. New device created with same name as old one.
860 * 4. ovs-brcompatd notified, removes device from bridge.
862 * There's no a priori reason that in this situation that the
863 * new device with the same name should remain in the bridge;
864 * on the contrary, that would be unexpected. *But* there is
865 * one important situation where, if we do this, bad things
866 * happen. This is the case of XenServer Tools version 5.0.0,
867 * which on boot of a Windows VM cause something like this to
868 * happen on the Xen host:
870 * i. Create tap1.0 and vif1.0.
872 * iii. Delete vif1.0.
873 * iv. Re-create vif1.0.
875 * (XenServer Tools 5.5.0 does not exhibit this behavior, and
876 * neither does a VM without Tools installed at all.@.)
878 * Steps iii and iv happen within a few seconds of each other.
879 * Step iv causes /etc/xensource/scripts/vif to run, which in
880 * turn calls ovs-cfg-mod to add the new device to the bridge.
881 * If step iv happens after step 4 (in our first list of
882 * steps), then all is well, but if it happens between 3 and 4
883 * (which can easily happen if ovs-brcompatd has to wait to
884 * lock the configuration file), then we will remove the new
885 * incarnation from the bridge instead of the old one!
887 * So, to avoid this problem, we do nothing here. This is
888 * strictly incorrect except for this one particular case, and
889 * perhaps that will bite us someday. If that happens, then we
890 * will have to somehow track network devices by ifindex, since
891 * a new device will have a new ifindex even if it has the same
892 * name as an old device.
894 VLOG_INFO("kernel reported network device %s removed but "
895 "a device by that name exists (XS Tools 5.0.0?)",
905 main(int argc
, char *argv
[])
907 struct unixctl_server
*unixctl
;
910 set_program_name(argv
[0]);
911 register_fault_handlers();
914 parse_options(argc
, argv
);
915 signal(SIGPIPE
, SIG_IGN
);
918 die_if_already_running();
921 retval
= unixctl_server_create(NULL
, &unixctl
);
923 ovs_fatal(retval
, "could not listen for vlog connections");
926 if (brc_open(&brc_sock
)) {
927 ovs_fatal(0, "could not open brcompat socket. Check "
928 "\"brcompat\" kernel module.");
932 if (nl_sock_create(NETLINK_ROUTE
, RTNLGRP_LINK
, 0, 0, &rtnl_sock
)) {
933 ovs_fatal(0, "could not create rtnetlink socket");
939 ovs_fatal(retval
, "could not read config file");
943 unixctl_server_run(unixctl
);
946 /* If 'prune_timeout' is non-zero, we actively prune from the
947 * config file any 'bridge.<br_name>.port' entries that are no
948 * longer valid. We use two methods:
950 * 1) The kernel explicitly notifies us of removed ports
951 * through the RTNL messages.
953 * 2) We periodically check all ports associated with bridges
954 * to see if they no longer exist.
960 nl_sock_wait(rtnl_sock
, POLLIN
);
961 poll_timer_wait(prune_timeout
);
964 nl_sock_wait(brc_sock
, POLLIN
);
965 unixctl_server_wait(unixctl
);
973 validate_appctl_command(void)
979 for (p
= strchr(appctl_command
, '%'); p
; p
= strchr(p
+ 2, '%')) {
982 } else if (p
[1] == 's') {
985 ovs_fatal(0, "only '%%s' and '%%%%' allowed in --appctl-command");
989 ovs_fatal(0, "'%%s' must appear exactly once in --appctl-command");
994 parse_options(int argc
, char *argv
[])
997 OPT_LOCK_TIMEOUT
= UCHAR_MAX
+ 1,
1001 LEAK_CHECKER_OPTION_ENUMS
1003 static struct option long_options
[] = {
1004 {"help", no_argument
, 0, 'h'},
1005 {"version", no_argument
, 0, 'V'},
1006 {"lock-timeout", required_argument
, 0, OPT_LOCK_TIMEOUT
},
1007 {"prune-timeout", required_argument
, 0, OPT_PRUNE_TIMEOUT
},
1008 {"appctl-command", required_argument
, 0, OPT_APPCTL_COMMAND
},
1009 DAEMON_LONG_OPTIONS
,
1011 LEAK_CHECKER_LONG_OPTIONS
,
1014 char *short_options
= long_options_to_short_options(long_options
);
1017 appctl_command
= xasprintf("%s/ovs-appctl -t "
1018 "%s/ovs-vswitchd.`cat %s/ovs-vswitchd.pid`.ctl "
1020 ovs_bindir
, ovs_rundir
, ovs_rundir
);
1024 c
= getopt_long(argc
, argv
, short_options
, long_options
, NULL
);
1035 OVS_PRINT_VERSION(0, 0);
1038 case OPT_LOCK_TIMEOUT
:
1039 lock_timeout
= atoi(optarg
);
1042 case OPT_PRUNE_TIMEOUT
:
1043 prune_timeout
= atoi(optarg
) * 1000;
1046 case OPT_APPCTL_COMMAND
:
1047 appctl_command
= optarg
;
1050 VLOG_OPTION_HANDLERS
1051 DAEMON_OPTION_HANDLERS
1052 LEAK_CHECKER_OPTION_HANDLERS
1061 free(short_options
);
1063 validate_appctl_command();
1069 ovs_fatal(0, "exactly one non-option argument required; "
1070 "use --help for usage");
1074 config_file
= argv
[0];
1075 error
= cfg_set_file(config_file
);
1077 ovs_fatal(error
, "failed to add configuration file \"%s\"",
1085 printf("%s: bridge compatibility front-end for ovs-vswitchd\n"
1086 "usage: %s [OPTIONS] CONFIG\n"
1087 "CONFIG is the configuration file used by ovs-vswitchd.\n",
1088 program_name
, program_name
);
1089 printf("\nConfiguration options:\n"
1090 " --appctl-command=COMMAND shell command to run ovs-appctl\n"
1091 " --prune-timeout=SECS wait at most SECS before pruning ports\n"
1092 " --lock-timeout=MSECS wait at most MSECS for CONFIG to unlock\n"
1096 printf("\nOther options:\n"
1097 " -h, --help display this help message\n"
1098 " -V, --version display version information\n");
1099 leak_checker_usage();
1100 printf("\nThe default appctl command is:\n%s\n", appctl_command
);