+ /* Not strictly necessary but seems cleaner. */
+ memset(&rule->flow, 0, sizeof rule->flow);
+}
+
+static void
+set_in_port(struct in_band_rule *rule, uint16_t odp_port)
+{
+ rule->wildcards &= ~OFPFW_IN_PORT;
+ rule->flow.in_port = odp_port;
+}
+
+static void
+set_dl_type(struct in_band_rule *rule, uint16_t dl_type)
+{
+ rule->wildcards &= ~OFPFW_DL_TYPE;
+ rule->flow.dl_type = dl_type;
+}
+
+static void
+set_dl_src(struct in_band_rule *rule, const uint8_t dl_src[ETH_ADDR_LEN])
+{
+ rule->wildcards &= ~OFPFW_DL_SRC;
+ memcpy(rule->flow.dl_src, dl_src, ETH_ADDR_LEN);
+}
+
+static void
+set_dl_dst(struct in_band_rule *rule, const uint8_t dl_dst[ETH_ADDR_LEN])
+{
+ rule->wildcards &= ~OFPFW_DL_DST;
+ memcpy(rule->flow.dl_dst, dl_dst, ETH_ADDR_LEN);
+}
+
+static void
+set_tp_src(struct in_band_rule *rule, uint16_t tp_src)
+{
+ rule->wildcards &= ~OFPFW_TP_SRC;
+ rule->flow.tp_src = tp_src;
+}
+
+static void
+set_tp_dst(struct in_band_rule *rule, uint16_t tp_dst)
+{
+ rule->wildcards &= ~OFPFW_TP_DST;
+ rule->flow.tp_dst = tp_dst;
+}
+
+static void
+set_nw_proto(struct in_band_rule *rule, uint8_t nw_proto)
+{
+ rule->wildcards &= ~OFPFW_NW_PROTO;
+ rule->flow.nw_proto = nw_proto;
+}
+
+static void
+set_nw_src(struct in_band_rule *rule, const struct in_addr nw_src)
+{
+ rule->wildcards &= ~OFPFW_NW_SRC_MASK;
+ rule->flow.nw_src = nw_src.s_addr;
+}
+
+static void
+set_nw_dst(struct in_band_rule *rule, const struct in_addr nw_dst)
+{
+ rule->wildcards &= ~OFPFW_NW_DST_MASK;
+ rule->flow.nw_dst = nw_dst.s_addr;
+}
+
+static void
+make_rules(struct in_band *ib,
+ void (*cb)(struct in_band *, const struct in_band_rule *))
+{
+ struct in_band_rule rule;
+ size_t i;
+
+ if (!eth_addr_is_zero(ib->installed_local_mac)) {
+ /* (a) Allow DHCP requests sent from the local port. */
+ init_rule(&rule, IBR_FROM_LOCAL_DHCP);
+ set_in_port(&rule, ODPP_LOCAL);
+ set_dl_type(&rule, htons(ETH_TYPE_IP));
+ set_dl_src(&rule, ib->installed_local_mac);
+ set_nw_proto(&rule, IP_TYPE_UDP);
+ set_tp_src(&rule, htons(DHCP_CLIENT_PORT));
+ set_tp_dst(&rule, htons(DHCP_SERVER_PORT));
+ cb(ib, &rule);
+
+ /* (b) Allow ARP replies to the local port's MAC address. */
+ init_rule(&rule, IBR_TO_LOCAL_ARP);
+ set_dl_type(&rule, htons(ETH_TYPE_ARP));
+ set_dl_dst(&rule, ib->installed_local_mac);
+ set_nw_proto(&rule, ARP_OP_REPLY);
+ cb(ib, &rule);
+
+ /* (c) Allow ARP requests from the local port's MAC address. */
+ init_rule(&rule, IBR_FROM_LOCAL_ARP);
+ set_dl_type(&rule, htons(ETH_TYPE_ARP));
+ set_dl_src(&rule, ib->installed_local_mac);
+ set_nw_proto(&rule, ARP_OP_REQUEST);
+ cb(ib, &rule);