summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--trafgen_l2.c44
-rw-r--r--trafgen_l3.c24
-rw-r--r--trafgen_l4.c28
-rw-r--r--trafgen_parser.y64
-rw-r--r--trafgen_proto.c144
-rw-r--r--trafgen_proto.h52
6 files changed, 179 insertions, 177 deletions
diff --git a/trafgen_l2.c b/trafgen_l2.c
index b27c9dd..5fc0a0d 100644
--- a/trafgen_l2.c
+++ b/trafgen_l2.c
@@ -40,14 +40,14 @@ static uint16_t pid_to_eth(enum proto_id pid)
static void eth_set_next_proto(struct proto_hdr *hdr, enum proto_id pid)
{
- proto_field_set_default_be16(hdr, ETH_TYPE, pid_to_eth(pid));
+ proto_hdr_field_set_default_be16(hdr, ETH_TYPE, pid_to_eth(pid));
}
static void eth_header_init(struct proto_hdr *hdr)
{
proto_header_fields_add(hdr, eth_fields, array_size(eth_fields));
- proto_field_set_default_dev_mac(hdr, ETH_SRC_ADDR);
+ proto_hdr_field_set_default_dev_mac(hdr, ETH_SRC_ADDR);
}
static const struct proto_ops eth_proto_ops = {
@@ -69,10 +69,10 @@ static void pause_header_init(struct proto_hdr *hdr)
struct proto_hdr *lower;
lower = proto_lower_default_add(hdr, PROTO_ETH);
- proto_field_set_default_bytes(lower, ETH_DST_ADDR, eth_dst);
+ proto_hdr_field_set_default_bytes(lower, ETH_DST_ADDR, eth_dst);
proto_header_fields_add(hdr, pause_fields, array_size(pause_fields));
- proto_field_set_default_be16(hdr, PAUSE_OPCODE, 0x1);
+ proto_hdr_field_set_default_be16(hdr, PAUSE_OPCODE, 0x1);
}
static struct proto_ops pause_proto_ops = {
@@ -109,10 +109,10 @@ static void pfc_header_init(struct proto_hdr *hdr)
struct proto_hdr *lower;
lower = proto_lower_default_add(hdr, PROTO_ETH);
- proto_field_set_default_bytes(lower, ETH_DST_ADDR, eth_dst);
+ proto_hdr_field_set_default_bytes(lower, ETH_DST_ADDR, eth_dst);
proto_header_fields_add(hdr, pfc_fields, array_size(pfc_fields));
- proto_field_set_default_be16(hdr, PFC_OPCODE, 0x0101);
+ proto_hdr_field_set_default_be16(hdr, PFC_OPCODE, 0x0101);
}
static struct proto_ops pfc_proto_ops = {
@@ -140,18 +140,18 @@ static void vlan_header_init(struct proto_hdr *hdr)
proto_header_fields_add(hdr, vlan_fields, array_size(vlan_fields));
if (lower->ops->id == PROTO_ETH)
- lower_etype = proto_field_get_u16(lower, ETH_TYPE);
+ lower_etype = proto_hdr_field_get_u16(lower, ETH_TYPE);
else if (lower->ops->id == PROTO_VLAN)
- lower_etype = proto_field_get_u16(lower, VLAN_ETYPE);
+ lower_etype = proto_hdr_field_get_u16(lower, VLAN_ETYPE);
- proto_field_set_be16(hdr, VLAN_ETYPE, lower_etype);
- proto_field_set_default_be16(hdr, VLAN_TPID, pid_to_eth(hdr->ops->id));
+ proto_hdr_field_set_be16(hdr, VLAN_ETYPE, lower_etype);
+ proto_hdr_field_set_default_be16(hdr, VLAN_TPID, pid_to_eth(hdr->ops->id));
}
static void vlan_set_next_proto(struct proto_hdr *hdr, enum proto_id pid)
{
if (pid != PROTO_VLAN)
- proto_field_set_be16(hdr, VLAN_ETYPE, pid_to_eth(pid));
+ proto_hdr_field_set_be16(hdr, VLAN_ETYPE, pid_to_eth(pid));
}
static const struct proto_ops vlan_proto_ops = {
@@ -180,20 +180,20 @@ static void arp_header_init(struct proto_hdr *hdr)
if (lower->ops->id == PROTO_ETH) {
const uint8_t bcast[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
- proto_field_set_default_bytes(lower, ETH_DST_ADDR, bcast);
+ proto_hdr_field_set_default_bytes(lower, ETH_DST_ADDR, bcast);
}
proto_header_fields_add(hdr, arp_fields, array_size(arp_fields));
/* Generate Announce request by default */
- proto_field_set_default_be16(hdr, ARP_HTYPE, ARPHRD_ETHER);
- proto_field_set_default_be16(hdr, ARP_PTYPE, ETH_P_IP);
- proto_field_set_default_u8(hdr, ARP_HLEN, 6);
- proto_field_set_default_u8(hdr, ARP_PLEN, 4);
- proto_field_set_default_be16(hdr, ARP_OPER, ARPOP_REQUEST);
- proto_field_set_default_dev_mac(hdr, ARP_SHA);
- proto_field_set_default_dev_ipv4(hdr, ARP_SPA);
- proto_field_set_default_dev_ipv4(hdr, ARP_TPA);
+ proto_hdr_field_set_default_be16(hdr, ARP_HTYPE, ARPHRD_ETHER);
+ proto_hdr_field_set_default_be16(hdr, ARP_PTYPE, ETH_P_IP);
+ proto_hdr_field_set_default_u8(hdr, ARP_HLEN, 6);
+ proto_hdr_field_set_default_u8(hdr, ARP_PLEN, 4);
+ proto_hdr_field_set_default_be16(hdr, ARP_OPER, ARPOP_REQUEST);
+ proto_hdr_field_set_default_dev_mac(hdr, ARP_SHA);
+ proto_hdr_field_set_default_dev_ipv4(hdr, ARP_SPA);
+ proto_hdr_field_set_default_dev_ipv4(hdr, ARP_TPA);
}
static const struct proto_ops arp_proto_ops = {
@@ -215,13 +215,13 @@ static void mpls_header_init(struct proto_hdr *hdr)
proto_header_fields_add(hdr, mpls_fields, array_size(mpls_fields));
- proto_field_set_default_be32(hdr, MPLS_LAST, 1);
+ proto_hdr_field_set_default_be32(hdr, MPLS_LAST, 1);
}
static void mpls_set_next_proto(struct proto_hdr *hdr, enum proto_id pid)
{
if (pid == PROTO_MPLS)
- proto_field_set_default_be32(hdr, MPLS_LAST, 0);
+ proto_hdr_field_set_default_be32(hdr, MPLS_LAST, 0);
}
static const struct proto_ops mpls_proto_ops = {
diff --git a/trafgen_l3.c b/trafgen_l3.c
index bce8ca9..4d67f58 100644
--- a/trafgen_l3.c
+++ b/trafgen_l3.c
@@ -38,8 +38,8 @@ static void ipv4_header_init(struct proto_hdr *hdr)
proto_header_fields_add(hdr, ipv4_fields, array_size(ipv4_fields));
- proto_field_set_default_u8(hdr, IP4_VER, 4);
- proto_field_set_default_u8(hdr, IP4_IHL, 5);
+ proto_hdr_field_set_default_u8(hdr, IP4_VER, 4);
+ proto_hdr_field_set_default_u8(hdr, IP4_IHL, 5);
}
static void ipv4_field_changed(struct proto_field *field)
@@ -61,14 +61,14 @@ static void ipv4_csum_update(struct proto_hdr *hdr)
if (hdr->is_csum_valid)
return;
- if (proto_field_is_set(hdr, IP4_CSUM))
+ if (proto_hdr_field_is_set(hdr, IP4_CSUM))
return;
pkt = packet_get(hdr->pkt_id);
- proto_field_set_default_u16(hdr, IP4_CSUM, 0);
+ proto_hdr_field_set_default_u16(hdr, IP4_CSUM, 0);
csum = htons(calc_csum(&pkt->payload[hdr->pkt_offset], hdr->len));
- proto_field_set_default_u16(hdr, IP4_CSUM, bswap_16(csum));
+ proto_hdr_field_set_default_u16(hdr, IP4_CSUM, bswap_16(csum));
hdr->is_csum_valid = true;
}
@@ -79,8 +79,8 @@ static void ipv4_packet_finish(struct proto_hdr *hdr)
uint16_t total_len;
total_len = pkt->len - hdr->pkt_offset;
- proto_field_set_default_be16(hdr, IP4_LEN, total_len);
- proto_field_set_default_dev_ipv4(hdr, IP4_SADDR);
+ proto_hdr_field_set_default_be16(hdr, IP4_LEN, total_len);
+ proto_hdr_field_set_default_dev_ipv4(hdr, IP4_SADDR);
ipv4_csum_update(hdr);
}
@@ -109,7 +109,7 @@ static void ipv4_set_next_proto(struct proto_hdr *hdr, enum proto_id pid)
bug();
}
- proto_field_set_default_u8(hdr, IP4_PROTO, ip_proto);
+ proto_hdr_field_set_default_u8(hdr, IP4_PROTO, ip_proto);
}
static const struct proto_ops ipv4_proto_ops = {
@@ -139,7 +139,7 @@ static void ipv6_header_init(struct proto_hdr *hdr)
proto_header_fields_add(hdr, ipv6_fields, array_size(ipv6_fields));
- proto_field_set_default_be32(hdr, IP6_VER, 6);
+ proto_hdr_field_set_default_be32(hdr, IP6_VER, 6);
}
static void ipv6_field_changed(struct proto_field *field)
@@ -159,8 +159,8 @@ static void ipv6_packet_finish(struct proto_hdr *hdr)
struct packet *pkt = current_packet();
uint16_t total_len = pkt->len - hdr->pkt_offset - IPV6_HDR_LEN;
- proto_field_set_default_be16(hdr, IP6_LEN, total_len);
- proto_field_set_default_dev_ipv6(hdr, IP6_SADDR);
+ proto_hdr_field_set_default_be16(hdr, IP6_LEN, total_len);
+ proto_hdr_field_set_default_dev_ipv6(hdr, IP6_SADDR);
}
static void ipv6_set_next_proto(struct proto_hdr *hdr, enum proto_id pid)
@@ -181,7 +181,7 @@ static void ipv6_set_next_proto(struct proto_hdr *hdr, enum proto_id pid)
bug();
}
- proto_field_set_default_u8(hdr, IP6_NEXT_HDR, ip_proto);
+ proto_hdr_field_set_default_u8(hdr, IP6_NEXT_HDR, ip_proto);
}
static const struct proto_ops ipv6_proto_ops = {
diff --git a/trafgen_l4.c b/trafgen_l4.c
index b3b0775..5a694b3 100644
--- a/trafgen_l4.c
+++ b/trafgen_l4.c
@@ -41,7 +41,7 @@ static void udp_csum_update(struct proto_hdr *hdr)
if (hdr->is_csum_valid)
return;
- if (proto_field_is_set(hdr, UDP_CSUM))
+ if (proto_hdr_field_is_set(hdr, UDP_CSUM))
return;
lower = proto_lower_header(hdr);
if (!lower)
@@ -49,7 +49,7 @@ static void udp_csum_update(struct proto_hdr *hdr)
total_len = packet_get(hdr->pkt_id)->len - hdr->pkt_offset;
- proto_field_set_default_be16(hdr, UDP_CSUM, 0);
+ proto_hdr_field_set_default_be16(hdr, UDP_CSUM, 0);
switch (lower->ops->id) {
case PROTO_IP4:
@@ -65,7 +65,7 @@ static void udp_csum_update(struct proto_hdr *hdr)
break;
}
- proto_field_set_default_be16(hdr, UDP_CSUM, bswap_16(csum));
+ proto_hdr_field_set_default_be16(hdr, UDP_CSUM, bswap_16(csum));
hdr->is_csum_valid = true;
}
@@ -75,7 +75,7 @@ static void udp_packet_finish(struct proto_hdr *hdr)
uint16_t total_len;
total_len = pkt->len - hdr->pkt_offset;
- proto_field_set_default_be16(hdr, UDP_LEN, total_len);
+ proto_hdr_field_set_default_be16(hdr, UDP_LEN, total_len);
udp_csum_update(hdr);
}
@@ -115,7 +115,7 @@ static void tcp_header_init(struct proto_hdr *hdr)
proto_header_fields_add(hdr, tcp_fields, array_size(tcp_fields));
- proto_field_set_default_be16(hdr, TCP_DOFF, 5);
+ proto_hdr_field_set_default_be16(hdr, TCP_DOFF, 5);
}
static void tcp_field_changed(struct proto_field *field)
@@ -132,7 +132,7 @@ static void tcp_csum_update(struct proto_hdr *hdr)
if (hdr->is_csum_valid)
return;
- if (proto_field_is_set(hdr, TCP_CSUM))
+ if (proto_hdr_field_is_set(hdr, TCP_CSUM))
return;
if (!lower)
@@ -140,7 +140,7 @@ static void tcp_csum_update(struct proto_hdr *hdr)
total_len = pkt->len - hdr->pkt_offset;
- proto_field_set_default_be16(hdr, TCP_CSUM, 0);
+ proto_hdr_field_set_default_be16(hdr, TCP_CSUM, 0);
switch (lower->ops->id) {
case PROTO_IP4:
@@ -156,7 +156,7 @@ static void tcp_csum_update(struct proto_hdr *hdr)
break;
}
- proto_field_set_default_be16(hdr, TCP_CSUM, bswap_16(csum));
+ proto_hdr_field_set_default_be16(hdr, TCP_CSUM, bswap_16(csum));
hdr->is_csum_valid = true;
}
@@ -196,14 +196,14 @@ static void icmpv4_csum_update(struct proto_hdr *hdr)
if (hdr->is_csum_valid)
return;
- if (proto_field_is_set(hdr, ICMPV4_CSUM))
+ if (proto_hdr_field_is_set(hdr, ICMPV4_CSUM))
return;
pkt = packet_get(hdr->pkt_id);
- proto_field_set_default_u16(hdr, ICMPV4_CSUM, 0);
+ proto_hdr_field_set_default_u16(hdr, ICMPV4_CSUM, 0);
csum = htons(calc_csum(proto_header_ptr(hdr), pkt->len - hdr->pkt_offset));
- proto_field_set_default_u16(hdr, ICMPV4_CSUM, bswap_16(csum));
+ proto_hdr_field_set_default_u16(hdr, ICMPV4_CSUM, bswap_16(csum));
hdr->is_csum_valid = true;
}
@@ -246,18 +246,18 @@ static void icmpv6_csum_update(struct proto_hdr *hdr)
return;
if (hdr->is_csum_valid)
return;
- if (proto_field_is_set(hdr, ICMPV6_CSUM))
+ if (proto_hdr_field_is_set(hdr, ICMPV6_CSUM))
return;
total_len = pkt->len - hdr->pkt_offset;
- proto_field_set_be16(hdr, ICMPV6_CSUM, 0);
+ proto_hdr_field_set_be16(hdr, ICMPV6_CSUM, 0);
if (likely(lower->ops->id == PROTO_IP6)) {
csum = p6_csum((void *) proto_header_ptr(lower), proto_header_ptr(hdr),
total_len, IPPROTO_ICMPV6);
- proto_field_set_be16(hdr, ICMPV6_CSUM, bswap_16(csum));
+ proto_hdr_field_set_be16(hdr, ICMPV6_CSUM, bswap_16(csum));
hdr->is_csum_valid = true;
}
}
diff --git a/trafgen_parser.y b/trafgen_parser.y
index 7e22a1d..bfeed2e 100644
--- a/trafgen_parser.y
+++ b/trafgen_parser.y
@@ -387,14 +387,14 @@ static void proto_add(enum proto_id pid)
static void proto_field_set(uint32_t fid)
{
- field_expr.field = proto_field_by_id(hdr, fid);
+ field_expr.field = proto_hdr_field_by_id(hdr, fid);
}
static void proto_field_func_setup(struct proto_field *field, struct proto_field_func *func)
{
struct packet_dyn *pkt_dyn;
- proto_field_func_add(field->hdr, field->id, func);
+ proto_hdr_field_func_add(field->hdr, field->id, func);
pkt_dyn = &packet_dyn[packetd_last];
pkt_dyn->flen++;
@@ -410,25 +410,25 @@ static void proto_field_expr_eval(void)
switch (field_expr.type) {
case FIELD_EXPR_NUMB:
if (field->len == 1)
- proto_field_set_u8(hdr, field->id, field_expr.val.number);
+ proto_hdr_field_set_u8(hdr, field->id, field_expr.val.number);
else if (field->len == 2)
- proto_field_set_be16(hdr, field->id, field_expr.val.number);
+ proto_hdr_field_set_be16(hdr, field->id, field_expr.val.number);
else if (field->len == 4)
- proto_field_set_be32(hdr, field->id, field_expr.val.number);
+ proto_hdr_field_set_be32(hdr, field->id, field_expr.val.number);
else
bug();
break;
case FIELD_EXPR_MAC:
- proto_field_set_bytes(hdr, field->id, field_expr.val.bytes);
+ proto_hdr_field_set_bytes(hdr, field->id, field_expr.val.bytes);
break;
case FIELD_EXPR_IP4_ADDR:
- proto_field_set_u32(hdr, field->id, field_expr.val.ip4_addr.s_addr);
+ proto_hdr_field_set_u32(hdr, field->id, field_expr.val.ip4_addr.s_addr);
break;
case FIELD_EXPR_IP6_ADDR:
- proto_field_set_bytes(hdr, field->id,
+ proto_hdr_field_set_bytes(hdr, field->id,
(uint8_t *)&field_expr.val.ip6_addr.s6_addr);
break;
@@ -878,9 +878,9 @@ vlan_expr
: vlan_field skip_white '=' skip_white field_value_expr
{ proto_field_expr_eval(); }
| K_1Q
- { proto_field_set_be16(hdr, VLAN_TPID, ETH_P_8021Q); }
+ { proto_hdr_field_set_be16(hdr, VLAN_TPID, ETH_P_8021Q); }
| K_1AD
- { proto_field_set_be16(hdr, VLAN_TPID, ETH_P_8021AD); }
+ { proto_hdr_field_set_be16(hdr, VLAN_TPID, ETH_P_8021AD); }
;
mpls_proto
@@ -945,13 +945,13 @@ arp_expr
{ proto_field_set(ARP_OPER);
proto_field_expr_eval(); }
| K_OPER skip_white '=' skip_white K_REQUEST
- { proto_field_set_be16(hdr, ARP_OPER, ARPOP_REQUEST); }
+ { proto_hdr_field_set_be16(hdr, ARP_OPER, ARPOP_REQUEST); }
| K_OPER skip_white '=' skip_white K_REPLY
- { proto_field_set_be16(hdr, ARP_OPER, ARPOP_REPLY); }
+ { proto_hdr_field_set_be16(hdr, ARP_OPER, ARPOP_REPLY); }
| K_REQUEST
- { proto_field_set_be16(hdr, ARP_OPER, ARPOP_REQUEST); }
+ { proto_hdr_field_set_be16(hdr, ARP_OPER, ARPOP_REQUEST); }
| K_REPLY
- { proto_field_set_be16(hdr, ARP_OPER, ARPOP_REPLY); }
+ { proto_hdr_field_set_be16(hdr, ARP_OPER, ARPOP_REPLY); }
;
arp
: K_ARP { proto_add(PROTO_ARP); }
@@ -987,8 +987,8 @@ ip4_field
ip4_expr
: ip4_field skip_white '=' skip_white field_value_expr
{ proto_field_expr_eval(); }
- | K_DF { proto_field_set_be16(hdr, IP4_DF, 1); }
- | K_MF { proto_field_set_be16(hdr, IP4_MF, 1); }
+ | K_DF { proto_hdr_field_set_be16(hdr, IP4_DF, 1); }
+ | K_MF { proto_hdr_field_set_be16(hdr, IP4_MF, 1); }
;
ip4
@@ -1053,11 +1053,11 @@ icmp4_expr
: icmp4_field skip_white '=' skip_white field_value_expr
{ proto_field_expr_eval(); }
| K_ECHO_REQUEST
- { proto_field_set_u8(hdr, ICMPV4_TYPE, ICMP_ECHO);
- proto_field_set_u8(hdr, ICMPV4_CODE, 0); }
+ { proto_hdr_field_set_u8(hdr, ICMPV4_TYPE, ICMP_ECHO);
+ proto_hdr_field_set_u8(hdr, ICMPV4_CODE, 0); }
| K_ECHO_REPLY
- { proto_field_set_u8(hdr, ICMPV4_TYPE, ICMP_ECHOREPLY);
- proto_field_set_u8(hdr, ICMPV4_CODE, 0); }
+ { proto_hdr_field_set_u8(hdr, ICMPV4_TYPE, ICMP_ECHOREPLY);
+ proto_hdr_field_set_u8(hdr, ICMPV4_CODE, 0); }
;
icmp4
@@ -1085,13 +1085,13 @@ icmp6_expr
{ proto_field_set(ICMPV6_TYPE);
proto_field_expr_eval(); }
| K_TYPE skip_white '=' K_ECHO_REQUEST
- { proto_field_set_u8(hdr, ICMPV6_TYPE, ICMPV6_ECHO_REQUEST); }
+ { proto_hdr_field_set_u8(hdr, ICMPV6_TYPE, ICMPV6_ECHO_REQUEST); }
| K_ECHO_REQUEST
- { proto_field_set_u8(hdr, ICMPV6_TYPE, ICMPV6_ECHO_REQUEST); }
+ { proto_hdr_field_set_u8(hdr, ICMPV6_TYPE, ICMPV6_ECHO_REQUEST); }
| K_TYPE skip_white '=' K_ECHO_REPLY
- { proto_field_set_u8(hdr, ICMPV6_TYPE, ICMPV6_ECHO_REPLY); }
+ { proto_hdr_field_set_u8(hdr, ICMPV6_TYPE, ICMPV6_ECHO_REPLY); }
| K_ECHO_REPLY
- { proto_field_set_u8(hdr, ICMPV6_TYPE, ICMPV6_ECHO_REPLY); }
+ { proto_hdr_field_set_u8(hdr, ICMPV6_TYPE, ICMPV6_ECHO_REPLY); }
;
icmp6
: K_ICMP6 { proto_add(PROTO_ICMP6); }
@@ -1147,14 +1147,14 @@ tcp_field
tcp_expr
: tcp_field skip_white '=' skip_white field_value_expr
{ proto_field_expr_eval(); }
- | K_CWR { proto_field_set_be16(hdr, TCP_CWR, 1); }
- | K_ECE { proto_field_set_be16(hdr, TCP_ECE, 1); }
- | K_URG { proto_field_set_be16(hdr, TCP_URG, 1); }
- | K_ACK { proto_field_set_be16(hdr, TCP_ACK, 1); }
- | K_PSH { proto_field_set_be16(hdr, TCP_PSH, 1); }
- | K_RST { proto_field_set_be16(hdr, TCP_RST, 1); }
- | K_SYN { proto_field_set_be16(hdr, TCP_SYN, 1); }
- | K_FIN { proto_field_set_be16(hdr, TCP_FIN, 1); }
+ | K_CWR { proto_hdr_field_set_be16(hdr, TCP_CWR, 1); }
+ | K_ECE { proto_hdr_field_set_be16(hdr, TCP_ECE, 1); }
+ | K_URG { proto_hdr_field_set_be16(hdr, TCP_URG, 1); }
+ | K_ACK { proto_hdr_field_set_be16(hdr, TCP_ACK, 1); }
+ | K_PSH { proto_hdr_field_set_be16(hdr, TCP_PSH, 1); }
+ | K_RST { proto_hdr_field_set_be16(hdr, TCP_RST, 1); }
+ | K_SYN { proto_hdr_field_set_be16(hdr, TCP_SYN, 1); }
+ | K_FIN { proto_hdr_field_set_be16(hdr, TCP_FIN, 1); }
;
tcp
diff --git a/trafgen_proto.c b/trafgen_proto.c
index 05fccb2..f862592 100644
--- a/trafgen_proto.c
+++ b/trafgen_proto.c
@@ -107,7 +107,7 @@ void proto_header_fields_add(struct proto_hdr *hdr,
}
}
-struct proto_field *proto_field_by_id(struct proto_hdr *hdr, uint32_t fid)
+struct proto_field *proto_hdr_field_by_id(struct proto_hdr *hdr, uint32_t fid)
{
/* Assume the fields are stored in the same order as the respective
* enum, so the index can be used for faster lookup here.
@@ -117,9 +117,9 @@ struct proto_field *proto_field_by_id(struct proto_hdr *hdr, uint32_t fid)
return &hdr->fields[fid];
}
-bool proto_field_is_set(struct proto_hdr *hdr, uint32_t fid)
+bool proto_hdr_field_is_set(struct proto_hdr *hdr, uint32_t fid)
{
- struct proto_field *field = proto_field_by_id(hdr, fid);
+ struct proto_field *field = proto_hdr_field_by_id(hdr, fid);
return field ? field->is_set : false;
}
@@ -233,10 +233,12 @@ static void __proto_field_set_bytes(struct proto_field *field,
field->is_set = true;
}
-void proto_field_set_bytes(struct proto_hdr *hdr, uint32_t fid,
- const uint8_t *bytes)
+void proto_hdr_field_set_bytes(struct proto_hdr *hdr, uint32_t fid,
+ const uint8_t *bytes)
{
- __proto_field_set_bytes(proto_field_by_id(hdr, fid), bytes, false, false);
+ struct proto_field *field = proto_hdr_field_by_id(hdr, fid);
+
+ __proto_field_set_bytes(field, bytes, false, false);
}
static uint8_t *__proto_field_get_bytes(struct proto_field *field)
@@ -244,110 +246,110 @@ static uint8_t *__proto_field_get_bytes(struct proto_field *field)
return &packet_get(field->hdr->pkt_id)->payload[field->pkt_offset];
}
-void proto_field_set_u8(struct proto_hdr *hdr, uint32_t fid, uint8_t val)
+void proto_hdr_field_set_u8(struct proto_hdr *hdr, uint32_t fid, uint8_t val)
{
- proto_field_set_bytes(hdr, fid, (uint8_t *)&val);
+ proto_hdr_field_set_bytes(hdr, fid, (uint8_t *)&val);
}
-uint8_t proto_field_get_u8(struct proto_hdr *hdr, uint32_t fid)
+uint8_t proto_hdr_field_get_u8(struct proto_hdr *hdr, uint32_t fid)
{
- struct proto_field *field = proto_field_by_id(hdr, fid);
+ struct proto_field *field = proto_hdr_field_by_id(hdr, fid);
uint8_t val = *__proto_field_get_bytes(field);
return field_unmask_and_unshift(field, val);
}
-void proto_field_set_u16(struct proto_hdr *hdr, uint32_t fid, uint16_t val)
+void proto_hdr_field_set_u16(struct proto_hdr *hdr, uint32_t fid, uint16_t val)
{
- proto_field_set_bytes(hdr, fid, (uint8_t *)&val);
+ proto_hdr_field_set_bytes(hdr, fid, (uint8_t *)&val);
}
-uint16_t proto_field_get_u16(struct proto_hdr *hdr, uint32_t fid)
+uint16_t proto_hdr_field_get_u16(struct proto_hdr *hdr, uint32_t fid)
{
- struct proto_field *field = proto_field_by_id(hdr, fid);
+ struct proto_field *field = proto_hdr_field_by_id(hdr, fid);
uint16_t val = *(uint16_t *)__proto_field_get_bytes(field);
return field_unmask_and_unshift(field, be16_to_cpu(val));
}
-void proto_field_set_u32(struct proto_hdr *hdr, uint32_t fid, uint32_t val)
+void proto_hdr_field_set_u32(struct proto_hdr *hdr, uint32_t fid, uint32_t val)
{
- proto_field_set_bytes(hdr, fid, (uint8_t *)&val);
+ proto_hdr_field_set_bytes(hdr, fid, (uint8_t *)&val);
}
-uint32_t proto_field_get_u32(struct proto_hdr *hdr, uint32_t fid)
+uint32_t proto_hdr_field_get_u32(struct proto_hdr *hdr, uint32_t fid)
{
- struct proto_field *field = proto_field_by_id(hdr, fid);
+ struct proto_field *field = proto_hdr_field_by_id(hdr, fid);
uint32_t val = *(uint32_t *)__proto_field_get_bytes(field);
return field_unmask_and_unshift(field, be32_to_cpu(val));
}
-void proto_field_set_default_bytes(struct proto_hdr *hdr, uint32_t fid,
- const uint8_t *bytes)
+void proto_hdr_field_set_default_bytes(struct proto_hdr *hdr, uint32_t fid,
+ const uint8_t *bytes)
{
- struct proto_field *field = proto_field_by_id(hdr, fid);
+ struct proto_field *field = proto_hdr_field_by_id(hdr, fid);
__proto_field_set_bytes(field, bytes, true, false);
}
-void proto_field_set_default_u8(struct proto_hdr *hdr, uint32_t fid, uint8_t val)
+void proto_hdr_field_set_default_u8(struct proto_hdr *hdr, uint32_t fid, uint8_t val)
{
- struct proto_field *field = proto_field_by_id(hdr, fid);
+ struct proto_field *field = proto_hdr_field_by_id(hdr, fid);
__proto_field_set_bytes(field, (uint8_t *)&val, true, false);
}
-void proto_field_set_default_u16(struct proto_hdr *hdr, uint32_t fid, uint16_t val)
+void proto_hdr_field_set_default_u16(struct proto_hdr *hdr, uint32_t fid, uint16_t val)
{
- struct proto_field *field = proto_field_by_id(hdr, fid);
+ struct proto_field *field = proto_hdr_field_by_id(hdr, fid);
__proto_field_set_bytes(field, (uint8_t *)&val, true, false);
}
-void proto_field_set_default_u32(struct proto_hdr *hdr, uint32_t fid, uint32_t val)
+void proto_hdr_field_set_default_u32(struct proto_hdr *hdr, uint32_t fid, uint32_t val)
{
- struct proto_field *field = proto_field_by_id(hdr, fid);
+ struct proto_field *field = proto_hdr_field_by_id(hdr, fid);
__proto_field_set_bytes(field, (uint8_t *)&val, true, false);
}
-void proto_field_set_be16(struct proto_hdr *hdr, uint32_t fid, uint16_t val)
+void proto_hdr_field_set_be16(struct proto_hdr *hdr, uint32_t fid, uint16_t val)
{
- struct proto_field *field = proto_field_by_id(hdr, fid);
+ struct proto_field *field = proto_hdr_field_by_id(hdr, fid);
__proto_field_set_bytes(field, (uint8_t *)&val, false, true);
}
-void proto_field_set_be32(struct proto_hdr *hdr, uint32_t fid, uint32_t val)
+void proto_hdr_field_set_be32(struct proto_hdr *hdr, uint32_t fid, uint32_t val)
{
- struct proto_field *field = proto_field_by_id(hdr, fid);
+ struct proto_field *field = proto_hdr_field_by_id(hdr, fid);
__proto_field_set_bytes(field, (uint8_t *)&val, false, true);
}
-void proto_field_set_default_be16(struct proto_hdr *hdr, uint32_t fid, uint16_t val)
+void proto_hdr_field_set_default_be16(struct proto_hdr *hdr, uint32_t fid, uint16_t val)
{
- struct proto_field *field = proto_field_by_id(hdr, fid);
+ struct proto_field *field = proto_hdr_field_by_id(hdr, fid);
__proto_field_set_bytes(field, (uint8_t *)&val, true, true);
}
-void proto_field_set_default_be32(struct proto_hdr *hdr, uint32_t fid, uint32_t val)
+void proto_hdr_field_set_default_be32(struct proto_hdr *hdr, uint32_t fid, uint32_t val)
{
- struct proto_field *field = proto_field_by_id(hdr, fid);
+ struct proto_field *field = proto_hdr_field_by_id(hdr, fid);
__proto_field_set_bytes(field, (uint8_t *)&val, true, true);
}
-static void __proto_field_set_dev_mac(struct proto_hdr *hdr, uint32_t fid,
- bool is_default)
+static void __proto_hdr_field_set_dev_mac(struct proto_hdr *hdr, uint32_t fid,
+ bool is_default)
{
- struct proto_field *field = proto_field_by_id(hdr, fid);
+ struct proto_field *field = proto_hdr_field_by_id(hdr, fid);
uint8_t mac[ETH_ALEN];
int ret;
- if (proto_field_is_set(hdr, fid))
+ if (proto_hdr_field_is_set(hdr, fid))
return;
ret = device_hw_address(ctx.dev, mac, sizeof(mac));
@@ -357,25 +359,25 @@ static void __proto_field_set_dev_mac(struct proto_hdr *hdr, uint32_t fid,
__proto_field_set_bytes(field, mac, is_default, false);
}
-void proto_field_set_dev_mac(struct proto_hdr *hdr, uint32_t fid)
+void proto_hdr_field_set_dev_mac(struct proto_hdr *hdr, uint32_t fid)
{
- __proto_field_set_dev_mac(hdr, fid, false);
+ __proto_hdr_field_set_dev_mac(hdr, fid, false);
}
-void proto_field_set_default_dev_mac(struct proto_hdr *hdr, uint32_t fid)
+void proto_hdr_field_set_default_dev_mac(struct proto_hdr *hdr, uint32_t fid)
{
- __proto_field_set_dev_mac(hdr, fid, true);
+ __proto_hdr_field_set_dev_mac(hdr, fid, true);
}
-static void __proto_field_set_dev_ipv4(struct proto_hdr *hdr, uint32_t fid,
- bool is_default)
+static void __proto_hdr_field_set_dev_ipv4(struct proto_hdr *hdr, uint32_t fid,
+ bool is_default)
{
- struct proto_field *field = proto_field_by_id(hdr, fid);
+ struct proto_field *field = proto_hdr_field_by_id(hdr, fid);
struct sockaddr_storage ss = { };
struct sockaddr_in *ss4;
int ret;
- if (proto_field_is_set(hdr, fid))
+ if (proto_hdr_field_is_set(hdr, fid))
return;
ret = device_address(ctx.dev, AF_INET, &ss);
@@ -388,25 +390,25 @@ static void __proto_field_set_dev_ipv4(struct proto_hdr *hdr, uint32_t fid,
__proto_field_set_bytes(field, (uint8_t *)&ss4->sin_addr.s_addr, is_default, false);
}
-void proto_field_set_dev_ipv4(struct proto_hdr *hdr, uint32_t fid)
+void proto_hdr_field_set_dev_ipv4(struct proto_hdr *hdr, uint32_t fid)
{
- __proto_field_set_dev_ipv4(hdr, fid, false);
+ __proto_hdr_field_set_dev_ipv4(hdr, fid, false);
}
-void proto_field_set_default_dev_ipv4(struct proto_hdr *hdr, uint32_t fid)
+void proto_hdr_field_set_default_dev_ipv4(struct proto_hdr *hdr, uint32_t fid)
{
- __proto_field_set_dev_ipv4(hdr, fid, true);
+ __proto_hdr_field_set_dev_ipv4(hdr, fid, true);
}
-static void __proto_field_set_dev_ipv6(struct proto_hdr *hdr, uint32_t fid,
- bool is_default)
+static void __proto_hdr_field_set_dev_ipv6(struct proto_hdr *hdr, uint32_t fid,
+ bool is_default)
{
- struct proto_field *field = proto_field_by_id(hdr, fid);
+ struct proto_field *field = proto_hdr_field_by_id(hdr, fid);
struct sockaddr_storage ss = { };
struct sockaddr_in6 *ss6;
int ret;
- if (proto_field_is_set(hdr, fid))
+ if (proto_hdr_field_is_set(hdr, fid))
return;
ret = device_address(ctx.dev, AF_INET6, &ss);
@@ -419,14 +421,14 @@ static void __proto_field_set_dev_ipv6(struct proto_hdr *hdr, uint32_t fid,
__proto_field_set_bytes(field, (uint8_t *)&ss6->sin6_addr.s6_addr, is_default, false);
}
-void proto_field_set_dev_ipv6(struct proto_hdr *hdr, uint32_t fid)
+void proto_hdr_field_set_dev_ipv6(struct proto_hdr *hdr, uint32_t fid)
{
- __proto_field_set_dev_ipv6(hdr, fid, false);
+ __proto_hdr_field_set_dev_ipv6(hdr, fid, false);
}
-void proto_field_set_default_dev_ipv6(struct proto_hdr *hdr, uint32_t fid)
+void proto_hdr_field_set_default_dev_ipv6(struct proto_hdr *hdr, uint32_t fid)
{
- __proto_field_set_dev_ipv6(hdr, fid, true);
+ __proto_hdr_field_set_dev_ipv6(hdr, fid, true);
}
void protos_init(const char *dev)
@@ -484,11 +486,11 @@ static inline uint32_t field_inc(struct proto_field *field)
static void field_inc_func(struct proto_field *field)
{
if (field->len == 1) {
- proto_field_set_u8(field->hdr, field->id, field_inc(field));
+ proto_hdr_field_set_u8(field->hdr, field->id, field_inc(field));
} else if (field->len == 2) {
- proto_field_set_be16(field->hdr, field->id, field_inc(field));
+ proto_hdr_field_set_be16(field->hdr, field->id, field_inc(field));
} else if (field->len == 4) {
- proto_field_set_be32(field->hdr, field->id, field_inc(field));
+ proto_hdr_field_set_be32(field->hdr, field->id, field_inc(field));
} else if (field->len > 4) {
uint8_t *bytes = __proto_field_get_bytes(field);
@@ -506,13 +508,13 @@ static inline uint32_t field_rand(struct proto_field *field)
static void field_rnd_func(struct proto_field *field)
{
if (field->len == 1) {
- proto_field_set_u8(field->hdr, field->id,
+ proto_hdr_field_set_u8(field->hdr, field->id,
(uint8_t) field_rand(field));
} else if (field->len == 2) {
- proto_field_set_be16(field->hdr, field->id,
+ proto_hdr_field_set_be16(field->hdr, field->id,
(uint16_t) field_rand(field));
} else if (field->len == 4) {
- proto_field_set_be32(field->hdr, field->id,
+ proto_hdr_field_set_be32(field->hdr, field->id,
(uint32_t) field_rand(field));
} else if (field->len > 4) {
uint8_t *bytes = __proto_field_get_bytes(field);
@@ -523,10 +525,10 @@ static void field_rnd_func(struct proto_field *field)
}
}
-void proto_field_func_add(struct proto_hdr *hdr, uint32_t fid,
- struct proto_field_func *func)
+void proto_hdr_field_func_add(struct proto_hdr *hdr, uint32_t fid,
+ struct proto_field_func *func)
{
- struct proto_field *field = proto_field_by_id(hdr, fid);
+ struct proto_field *field = proto_hdr_field_by_id(hdr, fid);
bug_on(!func);
@@ -540,11 +542,11 @@ void proto_field_func_add(struct proto_hdr *hdr, uint32_t fid,
if (func->type & PROTO_FIELD_FUNC_MIN)
field->func.val = func->min;
else if (field->len == 1)
- field->func.val = proto_field_get_u8(hdr, fid);
+ field->func.val = proto_hdr_field_get_u8(hdr, fid);
else if (field->len == 2)
- field->func.val = proto_field_get_u16(hdr, fid);
+ field->func.val = proto_hdr_field_get_u16(hdr, fid);
else if (field->len == 4)
- field->func.val = proto_field_get_u32(hdr, fid);
+ field->func.val = proto_hdr_field_get_u32(hdr, fid);
else if (field->len > 4) {
uint8_t *bytes = __proto_field_get_bytes(field);
diff --git a/trafgen_proto.h b/trafgen_proto.h
index ec152b4..927fcb1 100644
--- a/trafgen_proto.h
+++ b/trafgen_proto.h
@@ -104,47 +104,47 @@ extern void proto_header_fields_add(struct proto_hdr *hdr,
const struct proto_field *fields,
size_t count);
-extern bool proto_field_is_set(struct proto_hdr *hdr, uint32_t fid);
-extern void proto_field_set_bytes(struct proto_hdr *hdr, uint32_t fid,
+extern bool proto_hdr_field_is_set(struct proto_hdr *hdr, uint32_t fid);
+extern void proto_hdr_field_set_bytes(struct proto_hdr *hdr, uint32_t fid,
const uint8_t *bytes);
-extern void proto_field_set_u8(struct proto_hdr *hdr, uint32_t fid, uint8_t val);
-extern uint8_t proto_field_get_u8(struct proto_hdr *hdr, uint32_t fid);
-extern void proto_field_set_u16(struct proto_hdr *hdr, uint32_t fid, uint16_t val);
-extern uint16_t proto_field_get_u16(struct proto_hdr *hdr, uint32_t fid);
-extern void proto_field_set_u32(struct proto_hdr *hdr, uint32_t fid, uint32_t val);
-extern uint32_t proto_field_get_u32(struct proto_hdr *hdr, uint32_t fid);
-
-extern void proto_field_set_default_bytes(struct proto_hdr *hdr, uint32_t fid,
+extern void proto_hdr_field_set_u8(struct proto_hdr *hdr, uint32_t fid, uint8_t val);
+extern uint8_t proto_hdr_field_get_u8(struct proto_hdr *hdr, uint32_t fid);
+extern void proto_hdr_field_set_u16(struct proto_hdr *hdr, uint32_t fid, uint16_t val);
+extern uint16_t proto_hdr_field_get_u16(struct proto_hdr *hdr, uint32_t fid);
+extern void proto_hdr_field_set_u32(struct proto_hdr *hdr, uint32_t fid, uint32_t val);
+extern uint32_t proto_hdr_field_get_u32(struct proto_hdr *hdr, uint32_t fid);
+
+extern void proto_hdr_field_set_default_bytes(struct proto_hdr *hdr, uint32_t fid,
const uint8_t *bytes);
-extern void proto_field_set_default_u8(struct proto_hdr *hdr, uint32_t fid,
+extern void proto_hdr_field_set_default_u8(struct proto_hdr *hdr, uint32_t fid,
uint8_t val);
-extern void proto_field_set_default_u16(struct proto_hdr *hdr, uint32_t fid,
+extern void proto_hdr_field_set_default_u16(struct proto_hdr *hdr, uint32_t fid,
uint16_t val);
-extern void proto_field_set_default_u32(struct proto_hdr *hdr, uint32_t fid,
+extern void proto_hdr_field_set_default_u32(struct proto_hdr *hdr, uint32_t fid,
uint32_t val);
-extern void proto_field_set_be16(struct proto_hdr *hdr, uint32_t fid, uint16_t val);
-extern void proto_field_set_be32(struct proto_hdr *hdr, uint32_t fid, uint32_t val);
+extern void proto_hdr_field_set_be16(struct proto_hdr *hdr, uint32_t fid, uint16_t val);
+extern void proto_hdr_field_set_be32(struct proto_hdr *hdr, uint32_t fid, uint32_t val);
-extern void proto_field_set_default_be16(struct proto_hdr *hdr, uint32_t fid,
+extern void proto_hdr_field_set_default_be16(struct proto_hdr *hdr, uint32_t fid,
uint16_t val);
-extern void proto_field_set_default_be32(struct proto_hdr *hdr, uint32_t fid,
+extern void proto_hdr_field_set_default_be32(struct proto_hdr *hdr, uint32_t fid,
uint32_t val);
-extern void proto_field_set_dev_mac(struct proto_hdr *hdr, uint32_t fid);
-extern void proto_field_set_default_dev_mac(struct proto_hdr *hdr, uint32_t fid);
+extern void proto_hdr_field_set_dev_mac(struct proto_hdr *hdr, uint32_t fid);
+extern void proto_hdr_field_set_default_dev_mac(struct proto_hdr *hdr, uint32_t fid);
-extern void proto_field_set_dev_ipv4(struct proto_hdr *hdr, uint32_t fid);
-extern void proto_field_set_default_dev_ipv4(struct proto_hdr *hdr, uint32_t fid);
+extern void proto_hdr_field_set_dev_ipv4(struct proto_hdr *hdr, uint32_t fid);
+extern void proto_hdr_field_set_default_dev_ipv4(struct proto_hdr *hdr, uint32_t fid);
-extern void proto_field_set_dev_ipv6(struct proto_hdr *hdr, uint32_t fid);
-extern void proto_field_set_default_dev_ipv6(struct proto_hdr *hdr, uint32_t fid);
+extern void proto_hdr_field_set_dev_ipv6(struct proto_hdr *hdr, uint32_t fid);
+extern void proto_hdr_field_set_default_dev_ipv6(struct proto_hdr *hdr, uint32_t fid);
extern void proto_field_dyn_apply(struct proto_field *field);
-extern void proto_field_func_add(struct proto_hdr *hdr, uint32_t fid,
- struct proto_field_func *func);
+extern void proto_hdr_field_func_add(struct proto_hdr *hdr, uint32_t fid,
+ struct proto_field_func *func);
-extern struct proto_field *proto_field_by_id(struct proto_hdr *hdr, uint32_t fid);
+extern struct proto_field *proto_hdr_field_by_id(struct proto_hdr *hdr, uint32_t fid);
#endif /* TRAFGEN_PROTO_H */