+ /* Figure out vswitchd bridge and VLAN. */
+ br_name = linux_bridge_to_ovs_bridge(linux_name, &br_vlan);
+ if (!br_name) {
+ error = EINVAL;
+ send_simple_reply(seq, error);
+ return error;
+ }
+
+ /* Fetch the forwarding database using ovs-appctl. */
+ output = capture_vsctl(appctl_program, "fdb/show", br_name,
+ (char *) NULL);
+ if (!output) {
+ error = ECHILD;
+ send_simple_reply(seq, error);
+ return error;
+ }
+
+ /* Fetch the MAC address for each interface on the bridge, so that we can
+ * fill in the is_local field in the response. */
+ sset_init(&ifaces);
+ get_bridge_ifaces(linux_name, &ifaces);
+ local_macs = xmalloc(sset_count(&ifaces) * sizeof *local_macs);
+ n_local_macs = 0;
+ SSET_FOR_EACH (iface_name, &ifaces) {
+ struct mac *mac = &local_macs[n_local_macs];
+ struct netdev *netdev;
+
+ error = netdev_open_default(iface_name, &netdev);
+ if (!error) {
+ if (!netdev_get_etheraddr(netdev, mac->addr)) {
+ n_local_macs++;
+ }
+ netdev_close(netdev);
+ }
+ }
+ sset_destroy(&ifaces);
+
+ /* Parse the response from ovs-appctl and convert it to binary format to
+ * pass back to the kernel. */
+ ofpbuf_init(&query_data, sizeof(struct __fdb_entry) * 8);
+ save_ptr = NULL;
+ strtok_r(output, "\n", &save_ptr); /* Skip header line. */
+ while (count > 0) {
+ struct __fdb_entry *entry;
+ int port, vlan, age;
+ uint8_t mac[ETH_ADDR_LEN];
+ char *line;
+ bool is_local;
+
+ line = strtok_r(NULL, "\n", &save_ptr);
+ if (!line) {
+ break;
+ }
+
+ if (sscanf(line, "%d %d "ETH_ADDR_SCAN_FMT" %d",
+ &port, &vlan, ETH_ADDR_SCAN_ARGS(mac), &age)
+ != 2 + ETH_ADDR_SCAN_COUNT + 1) {
+ static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 1);
+ VLOG_INFO_RL(&rl, "fdb/show output has invalid format: %s", line);
+ continue;
+ }
+
+ if (vlan != br_vlan) {
+ continue;
+ }
+
+ if (skip > 0) {
+ skip--;
+ continue;
+ }
+
+ /* Is this the MAC address of an interface on the bridge? */
+ is_local = false;
+ for (i = 0; i < n_local_macs; i++) {
+ if (eth_addr_equals(local_macs[i].addr, mac)) {
+ is_local = true;
+ break;
+ }
+ }
+
+ entry = ofpbuf_put_uninit(&query_data, sizeof *entry);
+ memcpy(entry->mac_addr, mac, ETH_ADDR_LEN);
+ entry->port_no = port & 0xff;
+ entry->is_local = is_local;
+ entry->ageing_timer_value = age * HZ;
+ entry->port_hi = (port & 0xff00) >> 8;
+ entry->pad0 = 0;
+ entry->unused = 0;
+ count--;