if (f->dl_type == htons(ETH_TYPE_IP)) {
if (!(w & FWW_NW_PROTO)) {
skip_proto = true;
- if (f->nw_proto == IP_TYPE_ICMP) {
+ if (f->nw_proto == IPPROTO_ICMP) {
ds_put_cstr(s, "icmp,");
- } else if (f->nw_proto == IP_TYPE_TCP) {
+ } else if (f->nw_proto == IPPROTO_TCP) {
ds_put_cstr(s, "tcp,");
- } else if (f->nw_proto == IP_TYPE_UDP) {
+ } else if (f->nw_proto == IPPROTO_UDP) {
ds_put_cstr(s, "udp,");
} else {
ds_put_cstr(s, "ip,");
if (!(w & FWW_NW_TOS)) {
ds_put_format(s, "nw_tos=%"PRIu8",", f->nw_tos);
}
- if (f->nw_proto == IP_TYPE_ICMP) {
+ if (f->nw_proto == IPPROTO_ICMP) {
if (!(w & FWW_TP_SRC)) {
ds_put_format(s, "icmp_type=%"PRIu16",", ntohs(f->tp_src));
}
flow_extract(&b, 0, 0, &flow);
if (flow.dl_type != htons(ETH_TYPE_IP)
- || flow.nw_proto != IP_TYPE_UDP
+ || flow.nw_proto != IPPROTO_UDP
|| flow.tp_dst != htons(DHCP_CLIENT_PORT)
|| !(eth_addr_is_broadcast(flow.dl_dst)
|| eth_addr_equals(flow.dl_dst, cli_mac))) {
nh.ip_id = 0;
nh.ip_frag_off = htons(IP_DONT_FRAGMENT);
nh.ip_ttl = 64;
- nh.ip_proto = IP_TYPE_UDP;
+ nh.ip_proto = IPPROTO_UDP;
nh.ip_csum = 0;
nh.ip_src = dhclient_get_ip(cli);
/* XXX need to use UDP socket for nonzero server IPs so that we can get
th.udp_csum = 0;
udp_csum = csum_add32(0, nh.ip_src);
udp_csum = csum_add32(udp_csum, nh.ip_dst);
- udp_csum = csum_add16(udp_csum, IP_TYPE_UDP << 8);
+ udp_csum = csum_add16(udp_csum, IPPROTO_UDP << 8);
udp_csum = csum_add16(udp_csum, th.udp_len);
udp_csum = csum_continue(udp_csum, &th, sizeof th);
th.udp_csum = csum_finish(csum_continue(udp_csum, b.data, b.size));
uint32_t *field;
field = type == ODP_ACTION_ATTR_SET_NW_SRC ? &nh->ip_src : &nh->ip_dst;
- if (key->nw_proto == IP_TYPE_TCP && packet->l7) {
+ if (key->nw_proto == IPPROTO_TCP && packet->l7) {
struct tcp_header *th = packet->l4;
th->tcp_csum = recalc_csum32(th->tcp_csum, *field, ip);
- } else if (key->nw_proto == IP_TYPE_UDP && packet->l7) {
+ } else if (key->nw_proto == IPPROTO_UDP && packet->l7) {
struct udp_header *uh = packet->l4;
if (uh->udp_csum) {
uh->udp_csum = recalc_csum32(uh->udp_csum, *field, ip);
flow->nw_proto = nh->ip_proto;
packet->l4 = b.data;
if (!IP_IS_FRAGMENT(nh->ip_frag_off)) {
- if (flow->nw_proto == IP_TYPE_TCP) {
+ if (flow->nw_proto == IPPROTO_TCP) {
const struct tcp_header *tcp = pull_tcp(&b);
if (tcp) {
flow->tp_src = tcp->tcp_src;
flow->tp_dst = tcp->tcp_dst;
packet->l7 = b.data;
}
- } else if (flow->nw_proto == IP_TYPE_UDP) {
+ } else if (flow->nw_proto == IPPROTO_UDP) {
const struct udp_header *udp = pull_udp(&b);
if (udp) {
flow->tp_src = udp->udp_src;
flow->tp_dst = udp->udp_dst;
packet->l7 = b.data;
}
- } else if (flow->nw_proto == IP_TYPE_ICMP) {
+ } else if (flow->nw_proto == IPPROTO_ICMP) {
const struct icmp_header *icmp = pull_icmp(&b);
if (icmp) {
flow->icmp_type = htons(icmp->icmp_type);
memset(stats, 0, sizeof(*stats));
if ((flow->dl_type == htons(ETH_TYPE_IP)) && packet->l4) {
- if ((flow->nw_proto == IP_TYPE_TCP) && packet->l7) {
+ if ((flow->nw_proto == IPPROTO_TCP) && packet->l7) {
struct tcp_header *tcp = packet->l4;
stats->tcp_flags = TCP_FLAGS(tcp->tcp_ctl);
}
if (fields.eth_type == htons(ETH_TYPE_IP)) {
fields.ip_addr = flow->nw_src ^ flow->nw_dst;
fields.ip_proto = flow->nw_proto;
- if (fields.ip_proto == IP_TYPE_TCP || fields.ip_proto == IP_TYPE_UDP) {
+ if (fields.ip_proto == IPPROTO_TCP || fields.ip_proto == IPPROTO_UDP) {
fields.tp_addr = flow->tp_src ^ flow->tp_dst;
} else {
fields.tp_addr = htons(0);
nxm_put_8(b, NXM_OF_IP_PROTO, flow->nw_proto);
switch (flow->nw_proto) {
/* TCP. */
- case IP_TYPE_TCP:
+ case IPPROTO_TCP:
if (!(wc & FWW_TP_SRC)) {
nxm_put_16(b, NXM_OF_TCP_SRC, flow->tp_src);
}
break;
/* UDP. */
- case IP_TYPE_UDP:
+ case IPPROTO_UDP:
if (!(wc & FWW_TP_SRC)) {
nxm_put_16(b, NXM_OF_UDP_SRC, flow->tp_src);
}
break;
/* ICMP. */
- case IP_TYPE_ICMP:
+ case IPPROTO_ICMP:
if (!(wc & FWW_TP_SRC)) {
nxm_put_8(b, NXM_OF_ICMP_TYPE, ntohs(flow->tp_src));
}
DEFINE_FIELD (OF_IP_PROTO, FWW_NW_PROTO, ETH_TYPE_IP, 0, false)
DEFINE_FIELD_M(OF_IP_SRC, 0, ETH_TYPE_IP, 0, false)
DEFINE_FIELD_M(OF_IP_DST, 0, ETH_TYPE_IP, 0, false)
-DEFINE_FIELD (OF_TCP_SRC, FWW_TP_SRC, ETH_TYPE_IP, IP_TYPE_TCP, false)
-DEFINE_FIELD (OF_TCP_DST, FWW_TP_DST, ETH_TYPE_IP, IP_TYPE_TCP, false)
-DEFINE_FIELD (OF_UDP_SRC, FWW_TP_SRC, ETH_TYPE_IP, IP_TYPE_UDP, false)
-DEFINE_FIELD (OF_UDP_DST, FWW_TP_DST, ETH_TYPE_IP, IP_TYPE_UDP, false)
-DEFINE_FIELD (OF_ICMP_TYPE, FWW_TP_SRC, ETH_TYPE_IP, IP_TYPE_ICMP, false)
-DEFINE_FIELD (OF_ICMP_CODE, FWW_TP_DST, ETH_TYPE_IP, IP_TYPE_ICMP, false)
+DEFINE_FIELD (OF_TCP_SRC, FWW_TP_SRC, ETH_TYPE_IP, IPPROTO_TCP, false)
+DEFINE_FIELD (OF_TCP_DST, FWW_TP_DST, ETH_TYPE_IP, IPPROTO_TCP, false)
+DEFINE_FIELD (OF_UDP_SRC, FWW_TP_SRC, ETH_TYPE_IP, IPPROTO_UDP, false)
+DEFINE_FIELD (OF_UDP_DST, FWW_TP_DST, ETH_TYPE_IP, IPPROTO_UDP, false)
+DEFINE_FIELD (OF_ICMP_TYPE, FWW_TP_SRC, ETH_TYPE_IP, IPPROTO_ICMP, false)
+DEFINE_FIELD (OF_ICMP_CODE, FWW_TP_DST, ETH_TYPE_IP, IPPROTO_ICMP, false)
DEFINE_FIELD (OF_ARP_OP, FWW_NW_PROTO, ETH_TYPE_ARP, 0, false)
DEFINE_FIELD_M(OF_ARP_SPA, 0, ETH_TYPE_ARP, 0, false)
DEFINE_FIELD_M(OF_ARP_TPA, 0, ETH_TYPE_ARP, 0, false)
ipv4_key->ipv4_proto = flow->nw_proto;
ipv4_key->ipv4_tos = flow->nw_tos;
- if (flow->nw_proto == IP_TYPE_TCP) {
+ if (flow->nw_proto == IPPROTO_TCP) {
struct odp_key_tcp *tcp_key;
tcp_key = nl_msg_put_unspec_uninit(buf, ODP_KEY_ATTR_TCP,
sizeof *tcp_key);
tcp_key->tcp_src = flow->tp_src;
tcp_key->tcp_dst = flow->tp_dst;
- } else if (flow->nw_proto == IP_TYPE_UDP) {
+ } else if (flow->nw_proto == IPPROTO_UDP) {
struct odp_key_udp *udp_key;
udp_key = nl_msg_put_unspec_uninit(buf, ODP_KEY_ATTR_UDP,
sizeof *udp_key);
udp_key->udp_src = flow->tp_src;
udp_key->udp_dst = flow->tp_dst;
- } else if (flow->nw_proto == IP_TYPE_ICMP) {
+ } else if (flow->nw_proto == IPPROTO_ICMP) {
struct odp_key_icmp *icmp_key;
icmp_key = nl_msg_put_unspec_uninit(buf, ODP_KEY_ATTR_ICMP,
break;
case TRANSITION(ODP_KEY_ATTR_IPV4, ODP_KEY_ATTR_TCP):
- if (flow->nw_proto != IP_TYPE_TCP) {
+ if (flow->nw_proto != IPPROTO_TCP) {
return EINVAL;
}
tcp_key = nl_attr_get(nla);
break;
case TRANSITION(ODP_KEY_ATTR_IPV4, ODP_KEY_ATTR_UDP):
- if (flow->nw_proto != IP_TYPE_UDP) {
+ if (flow->nw_proto != IPPROTO_UDP) {
return EINVAL;
}
udp_key = nl_attr_get(nla);
break;
case TRANSITION(ODP_KEY_ATTR_IPV4, ODP_KEY_ATTR_ICMP):
- if (flow->nw_proto != IP_TYPE_ICMP) {
+ if (flow->nw_proto != IPPROTO_ICMP) {
return EINVAL;
}
icmp_key = nl_attr_get(nla);
return 0;
case ODP_KEY_ATTR_IPV4:
- if (flow->nw_proto == IP_TYPE_TCP
- || flow->nw_proto == IP_TYPE_UDP
- || flow->nw_proto == IP_TYPE_ICMP) {
+ if (flow->nw_proto == IPPROTO_TCP
+ || flow->nw_proto == IPPROTO_UDP
+ || flow->nw_proto == IPPROTO_ICMP) {
return EINVAL;
}
return 0;
static const struct protocol protocols[] = {
{ "ip", ETH_TYPE_IP, 0 },
{ "arp", ETH_TYPE_ARP, 0 },
- { "icmp", ETH_TYPE_IP, IP_TYPE_ICMP },
- { "tcp", ETH_TYPE_IP, IP_TYPE_TCP },
- { "udp", ETH_TYPE_IP, IP_TYPE_UDP },
+ { "icmp", ETH_TYPE_IP, IPPROTO_ICMP },
+ { "tcp", ETH_TYPE_IP, IPPROTO_TCP },
+ { "udp", ETH_TYPE_IP, IPPROTO_UDP },
};
const struct protocol *p;
if (om->dl_type == htons(ETH_TYPE_IP)) {
if (!(w & OFPFW_NW_PROTO)) {
skip_proto = true;
- if (om->nw_proto == IP_TYPE_ICMP) {
+ if (om->nw_proto == IPPROTO_ICMP) {
ds_put_cstr(&f, "icmp,");
- } else if (om->nw_proto == IP_TYPE_TCP) {
+ } else if (om->nw_proto == IPPROTO_TCP) {
ds_put_cstr(&f, "tcp,");
- } else if (om->nw_proto == IP_TYPE_UDP) {
+ } else if (om->nw_proto == IPPROTO_UDP) {
ds_put_cstr(&f, "udp,");
} else {
ds_put_cstr(&f, "ip,");
}
print_wild(&f, "nw_tos=", w & OFPFW_NW_TOS, verbosity,
"%u", om->nw_tos);
- if (om->nw_proto == IP_TYPE_ICMP) {
+ if (om->nw_proto == IPPROTO_ICMP) {
print_wild(&f, "icmp_type=", w & OFPFW_ICMP_TYPE, verbosity,
"%d", ntohs(om->icmp_type));
print_wild(&f, "icmp_code=", w & OFPFW_ICMP_CODE, verbosity,
#define IP_ECN_MASK 0x03
#define IP_DSCP_MASK 0xfc
-#define IP_TYPE_ICMP 1
-#define IP_TYPE_TCP 6
-#define IP_TYPE_UDP 17
-
#define IP_VERSION 4
#define IP_DONT_FRAGMENT 0x4000 /* Don't fragment. */
/* Regardless of how the flow table is configured, we want to be
* able to see replies to our DHCP requests. */
if (flow->dl_type == htons(ETH_TYPE_IP)
- && flow->nw_proto == IP_TYPE_UDP
+ && flow->nw_proto == IPPROTO_UDP
&& flow->tp_src == htons(DHCP_SERVER_PORT)
&& flow->tp_dst == htons(DHCP_CLIENT_PORT)
&& packet->l7) {
/* Don't allow flows that would prevent DHCP replies from being seen
* by the local port. */
if (flow->dl_type == htons(ETH_TYPE_IP)
- && flow->nw_proto == IP_TYPE_UDP
+ && flow->nw_proto == IPPROTO_UDP
&& flow->tp_src == htons(DHCP_SERVER_PORT)
&& flow->tp_dst == htons(DHCP_CLIENT_PORT)) {
const struct nlattr *a;
cls_rule_set_in_port(&rule, ODPP_LOCAL);
cls_rule_set_dl_type(&rule, htons(ETH_TYPE_IP));
cls_rule_set_dl_src(&rule, ib->installed_local_mac);
- cls_rule_set_nw_proto(&rule, IP_TYPE_UDP);
+ cls_rule_set_nw_proto(&rule, IPPROTO_UDP);
cls_rule_set_tp_src(&rule, htons(DHCP_CLIENT_PORT));
cls_rule_set_tp_dst(&rule, htons(DHCP_SERVER_PORT));
cb(ib, &rule);
/* (h) Allow TCP traffic to the remote's IP and port. */
cls_rule_init_catchall(&rule, IBR_TO_REMOTE_TCP);
cls_rule_set_dl_type(&rule, htons(ETH_TYPE_IP));
- cls_rule_set_nw_proto(&rule, IP_TYPE_TCP);
+ cls_rule_set_nw_proto(&rule, IPPROTO_TCP);
cls_rule_set_nw_dst(&rule, a->sin_addr.s_addr);
cls_rule_set_tp_dst(&rule, a->sin_port);
cb(ib, &rule);
/* (i) Allow TCP traffic from the remote's IP and port. */
cls_rule_init_catchall(&rule, IBR_FROM_REMOTE_TCP);
cls_rule_set_dl_type(&rule, htons(ETH_TYPE_IP));
- cls_rule_set_nw_proto(&rule, IP_TYPE_TCP);
+ cls_rule_set_nw_proto(&rule, IPPROTO_TCP);
cls_rule_set_nw_src(&rule, a->sin_addr.s_addr);
cls_rule_set_tp_src(&rule, a->sin_port);
cb(ib, &rule);
nf_rec->init_time = htonl(nf_flow->created - nf->boot_time);
nf_rec->used_time = htonl(MAX(nf_flow->created, expired->used)
- nf->boot_time);
- if (expired->flow.nw_proto == IP_TYPE_ICMP) {
+ if (expired->flow.nw_proto == IPPROTO_ICMP) {
/* In NetFlow, the ICMP type and code are concatenated and
* placed in the 'dst_port' field. */
uint8_t type = ntohs(expired->flow.tp_src);
$flow{NW_PROTO} = 42;
} elsif ($attrs{TP_PROTO} eq 'TCP' ||
$attrs{TP_PROTO} eq 'TCP+options') {
- $flow{NW_PROTO} = 6; # IP_TYPE_TCP
+ $flow{NW_PROTO} = 6; # IPPROTO_TCP
$flow{TP_SRC} = 6667;
$flow{TP_DST} = 9998;
} elsif ($attrs{TP_PROTO} eq 'UDP') {
- $flow{NW_PROTO} = 17; # IP_TYPE_UDP
+ $flow{NW_PROTO} = 17; # IPPROTO_UDP
$flow{TP_SRC} = 1112;
$flow{TP_DST} = 2223;
} elsif ($attrs{TP_PROTO} eq 'ICMP') {
- $flow{NW_PROTO} = 1; # IP_TYPE_ICMP
+ $flow{NW_PROTO} = 1; # IPPROTO_ICMP
$flow{TP_SRC} = 8; # echo request
$flow{TP_DST} = 0; # code
} else {
{ 0x5e, 0x33, 0x7f, 0x5f, 0x1e, 0x99 } };
static uint8_t dl_dst_values[][6] = { { 0x4a, 0x27, 0x71, 0xae, 0x64, 0xc1 },
{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } };
-static uint8_t nw_proto_values[] = { IP_TYPE_TCP, IP_TYPE_ICMP };
+static uint8_t nw_proto_values[] = { IPPROTO_TCP, IPPROTO_ICMP };
static uint8_t nw_tos_values[] = { 49, 0 };
static void *values[CLS_N_FIELDS][2];