+static void
+queue_tx(struct rconn *rc, struct buffer *b)
+{
+ if (rconn_force_send(rc, b)) {
+ buffer_delete(b);
+ }
+}
+
+static bool
+is_controller_mac(const uint8_t dl_addr[ETH_ADDR_LEN],
+ struct rconn *controller)
+{
+ static uint32_t ip, last_nonzero_ip;
+ static uint8_t mac[ETH_ADDR_LEN], last_nonzero_mac[ETH_ADDR_LEN];
+ static time_t next_refresh = 0;
+
+ uint32_t last_ip = ip;
+
+ time_t now = time(0);
+
+ ip = rconn_get_ip(controller);
+ if (last_ip != ip || !next_refresh || now >= next_refresh) {
+ bool have_mac;
+
+ /* Look up MAC address. */
+ memset(mac, 0, sizeof mac);
+ if (ip) {
+ int retval = netdev_arp_lookup(of_device, ip, mac);
+ if (retval) {
+ VLOG_DBG("cannot look up controller hw address ("IP_FMT"): %s",
+ IP_ARGS(&ip), strerror(retval));
+ }
+ }
+ have_mac = !eth_addr_is_zero(mac);
+
+ /* Log changes in IP, MAC addresses. */
+ if (ip && ip != last_nonzero_ip) {
+ VLOG_DBG("controller IP address changed from "IP_FMT
+ " to "IP_FMT, IP_ARGS(&last_nonzero_ip), IP_ARGS(&ip));
+ last_nonzero_ip = ip;
+ }
+ if (have_mac && memcmp(last_nonzero_mac, mac, ETH_ADDR_LEN)) {
+ VLOG_DBG("controller MAC address changed from "ETH_ADDR_FMT" to "
+ ETH_ADDR_FMT,
+ ETH_ADDR_ARGS(last_nonzero_mac), ETH_ADDR_ARGS(mac));
+ memcpy(last_nonzero_mac, mac, ETH_ADDR_LEN);
+ }
+
+ /* Schedule next refresh.
+ *
+ * If we have an IP address but not a MAC address, then refresh
+ * quickly, since we probably will get a MAC address soon (via ARP).
+ * Otherwise, we can afford to wait a little while. */
+ next_refresh = now + (!ip || have_mac ? 10 : 1);
+ }
+ return !eth_addr_is_zero(mac) && eth_addr_equals(mac, dl_addr);
+}
+