Skip to content

Commit

Permalink
ofpbuf: Rename trivial _get_ functions without the "get".
Browse files Browse the repository at this point in the history
Code reads better without the "get", for example "ofpbuf_l3()"
v.s. "ofpbuf_get_l3()".  L4 payoad access functions still use the
"get" (e.g., "ofpbuf_get_tcp_payload()").

Signed-off-by: Jarno Rajahalme <[email protected]>
  • Loading branch information
Jarno Rajahalme committed Apr 3, 2014
1 parent 631cf30 commit 6b8c377
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 57 deletions.
4 changes: 2 additions & 2 deletions lib/cfm.c
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ cfm_compose_ccm(struct cfm *cfm, struct ofpbuf *packet,
eth_push_vlan(packet, htons(ETH_TYPE_VLAN), htons(tci));
}

ccm = ofpbuf_get_l3(packet);
ccm = ofpbuf_l3(packet);
ccm->mdlevel_version = 0;
ccm->opcode = CCM_OPCODE;
ccm->tlv_offset = 70;
Expand Down Expand Up @@ -719,7 +719,7 @@ cfm_process_heartbeat(struct cfm *cfm, const struct ofpbuf *p)
ovs_mutex_lock(&mutex);

eth = p->l2;
ccm = ofpbuf_at(p, (uint8_t *)ofpbuf_get_l3(p) - (uint8_t *)ofpbuf_data(p),
ccm = ofpbuf_at(p, (uint8_t *)ofpbuf_l3(p) - (uint8_t *)ofpbuf_data(p),
CCM_ACCEPT_LEN);

if (!ccm) {
Expand Down
2 changes: 1 addition & 1 deletion lib/lacp.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ parse_lacp_packet(const struct ofpbuf *b)
{
const struct lacp_pdu *pdu;

pdu = ofpbuf_at(b, (uint8_t *)ofpbuf_get_l3(b) - (uint8_t *)ofpbuf_data(b),
pdu = ofpbuf_at(b, (uint8_t *)ofpbuf_l3(b) - (uint8_t *)ofpbuf_data(b),
LACP_PDU_LEN);

if (pdu && pdu->subtype == 1
Expand Down
2 changes: 1 addition & 1 deletion lib/odp-execute.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ odp_set_tunnel_action(const struct nlattr *a, struct flow_tnl *tun_key)
static void
set_arp(struct ofpbuf *packet, const struct ovs_key_arp *arp_key)
{
struct arp_eth_header *arp = ofpbuf_get_l3(packet);
struct arp_eth_header *arp = ofpbuf_l3(packet);

arp->ar_op = arp_key->arp_op;
memcpy(arp->ar_sha, arp_key->arp_sha, ETH_ADDR_LEN);
Expand Down
8 changes: 4 additions & 4 deletions lib/ofp-print.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,16 @@ ofp_packet_to_string(const void *data, size_t len)
flow_extract(&buf, &md, &flow);
flow_format(&ds, &flow);

l4_size = ofpbuf_get_l4_size(&buf);
l4_size = ofpbuf_l4_size(&buf);

if (flow.nw_proto == IPPROTO_TCP && l4_size >= TCP_HEADER_LEN) {
struct tcp_header *th = ofpbuf_get_l4(&buf);
struct tcp_header *th = ofpbuf_l4(&buf);
ds_put_format(&ds, " tcp_csum:%"PRIx16, ntohs(th->tcp_csum));
} else if (flow.nw_proto == IPPROTO_UDP && l4_size >= UDP_HEADER_LEN) {
struct udp_header *uh = ofpbuf_get_l4(&buf);
struct udp_header *uh = ofpbuf_l4(&buf);
ds_put_format(&ds, " udp_csum:%"PRIx16, ntohs(uh->udp_csum));
} else if (flow.nw_proto == IPPROTO_SCTP && l4_size >= SCTP_HEADER_LEN) {
struct sctp_header *sh = ofpbuf_get_l4(&buf);
struct sctp_header *sh = ofpbuf_l4(&buf);
ds_put_format(&ds, " sctp_csum:%"PRIx32, ntohl(sh->sctp_csum));
}

Expand Down
24 changes: 12 additions & 12 deletions lib/ofp-util.c
Original file line number Diff line number Diff line change
Expand Up @@ -2176,7 +2176,7 @@ ofputil_encode_flow_mod(const struct ofputil_flow_mod *fm,
nfm->command = ofputil_tid_command(fm, protocol);
nfm->cookie = fm->new_cookie;
match_len = nx_put_match(msg, &fm->match, fm->cookie, fm->cookie_mask);
nfm = ofpbuf_get_l3(msg);
nfm = ofpbuf_l3(msg);
nfm->idle_timeout = htons(fm->idle_timeout);
nfm->hard_timeout = htons(fm->hard_timeout);
nfm->priority = htons(fm->priority);
Expand Down Expand Up @@ -2396,7 +2396,7 @@ ofputil_append_queue_get_config_reply(struct ofpbuf *reply,
struct ofp12_packet_queue *opq12;
ovs_be32 port;

qgcr11 = ofpbuf_get_l3(reply);
qgcr11 = ofpbuf_l3(reply);
port = qgcr11->port;

opq12 = ofpbuf_put_zeros(reply, sizeof *opq12);
Expand Down Expand Up @@ -2636,7 +2636,7 @@ ofputil_encode_flow_stats_request(const struct ofputil_flow_stats_request *fsr,
match_len = nx_put_match(msg, &fsr->match,
fsr->cookie, fsr->cookie_mask);

nfsr = ofpbuf_get_l3(msg);
nfsr = ofpbuf_l3(msg);
nfsr->out_port = htons(ofp_to_u16(fsr->out_port));
nfsr->match_len = htons(match_len);
nfsr->table_id = fsr->table_id;
Expand Down Expand Up @@ -2982,7 +2982,7 @@ ofputil_decode_aggregate_stats_reply(struct ofputil_aggregate_stats *stats,
ofpbuf_use_const(&msg, reply, ntohs(reply->length));
ofpraw_pull_assert(&msg);

asr = ofpbuf_get_l3(&msg);
asr = ofpbuf_l3(&msg);
stats->packet_count = ntohll(get_32aligned_be64(&asr->packet_count));
stats->byte_count = ntohll(get_32aligned_be64(&asr->byte_count));
stats->flow_count = ntohl(asr->flow_count);
Expand Down Expand Up @@ -3134,7 +3134,7 @@ ofputil_encode_flow_removed(const struct ofputil_flow_removed *fr,
nfr = ofpbuf_put_zeros(msg, sizeof *nfr);
match_len = nx_put_match(msg, &fr->match, 0, 0);

nfr = ofpbuf_get_l3(msg);
nfr = ofpbuf_l3(msg);
nfr->cookie = fr->cookie;
nfr->priority = htons(fr->priority);
nfr->reason = fr->reason;
Expand Down Expand Up @@ -3346,7 +3346,7 @@ ofputil_encode_nx_packet_in(const struct ofputil_packet_in *pin)
ofpbuf_put_zeros(packet, 2);
ofpbuf_put(packet, pin->packet, pin->packet_len);

npi = ofpbuf_get_l3(packet);
npi = ofpbuf_l3(packet);
npi->buffer_id = htonl(pin->buffer_id);
npi->total_len = htons(pin->total_len);
npi->reason = pin->reason;
Expand Down Expand Up @@ -3410,7 +3410,7 @@ ofputil_encode_ofp12_packet_in(const struct ofputil_packet_in *pin,
ofpbuf_put_zeros(packet, 2);
ofpbuf_put(packet, pin->packet, pin->packet_len);

opi = ofpbuf_get_l3(packet);
opi = ofpbuf_l3(packet);
opi->pi.buffer_id = htonl(pin->buffer_id);
opi->pi.total_len = htons(pin->total_len);
opi->pi.reason = pin->reason;
Expand Down Expand Up @@ -4629,7 +4629,7 @@ ofputil_decode_role_message(const struct ofp_header *oh,

if (raw == OFPRAW_OFPT12_ROLE_REQUEST ||
raw == OFPRAW_OFPT12_ROLE_REPLY) {
const struct ofp12_role_request *orr = ofpbuf_get_l3(&b);
const struct ofp12_role_request *orr = ofpbuf_l3(&b);

if (orr->role != htonl(OFPCR12_ROLE_NOCHANGE) &&
orr->role != htonl(OFPCR12_ROLE_EQUAL) &&
Expand All @@ -4650,7 +4650,7 @@ ofputil_decode_role_message(const struct ofp_header *oh,
}
} else if (raw == OFPRAW_NXT_ROLE_REQUEST ||
raw == OFPRAW_NXT_ROLE_REPLY) {
const struct nx_role_request *nrr = ofpbuf_get_l3(&b);
const struct nx_role_request *nrr = ofpbuf_l3(&b);

BUILD_ASSERT(NX_ROLE_OTHER + 1 == OFPCR12_ROLE_EQUAL);
BUILD_ASSERT(NX_ROLE_MASTER + 1 == OFPCR12_ROLE_MASTER);
Expand Down Expand Up @@ -4739,7 +4739,7 @@ ofputil_decode_role_status(const struct ofp_header *oh,
raw = ofpraw_pull_assert(&b);
ovs_assert(raw == OFPRAW_OFPT14_ROLE_STATUS);

r = ofpbuf_get_l3(&b);
r = ofpbuf_l3(&b);
if (r->role != htonl(OFPCR12_ROLE_NOCHANGE) &&
r->role != htonl(OFPCR12_ROLE_EQUAL) &&
r->role != htonl(OFPCR12_ROLE_MASTER) &&
Expand Down Expand Up @@ -5211,7 +5211,7 @@ ofputil_encode_packet_out(const struct ofputil_packet_out *po,
ofpacts_put_openflow_actions(po->ofpacts, po->ofpacts_len, msg,
ofp_version);

opo = ofpbuf_get_l3(msg);
opo = ofpbuf_l3(msg);
opo->buffer_id = htonl(po->buffer_id);
opo->in_port = htons(ofp_to_u16(po->in_port));
opo->actions_len = htons(ofpbuf_size(msg) - actions_ofs);
Expand All @@ -5229,7 +5229,7 @@ ofputil_encode_packet_out(const struct ofputil_packet_out *po,
ofpbuf_put_zeros(msg, sizeof *opo);
len = ofpacts_put_openflow_actions(po->ofpacts, po->ofpacts_len, msg,
ofp_version);
opo = ofpbuf_get_l3(msg);
opo = ofpbuf_l3(msg);
opo->buffer_id = htonl(po->buffer_id);
opo->in_port = ofputil_port_to_ofp11(po->in_port);
opo->actions_len = htons(len);
Expand Down
34 changes: 17 additions & 17 deletions lib/ofpbuf.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ static inline void ofpbuf_set_size(struct ofpbuf *, uint32_t);

void * ofpbuf_resize_l2(struct ofpbuf *, int increment);
void * ofpbuf_resize_l2_5(struct ofpbuf *, int increment);
static inline void * ofpbuf_get_l2_5(const struct ofpbuf *);
static inline void * ofpbuf_l2_5(const struct ofpbuf *);
static inline void ofpbuf_set_l2_5(struct ofpbuf *, void *);
static inline void * ofpbuf_get_l3(const struct ofpbuf *);
static inline void * ofpbuf_l3(const struct ofpbuf *);
static inline void ofpbuf_set_l3(struct ofpbuf *, void *);
static inline void * ofpbuf_get_l4(const struct ofpbuf *);
static inline void * ofpbuf_l4(const struct ofpbuf *);
static inline void ofpbuf_set_l4(struct ofpbuf *, void *);
static inline size_t ofpbuf_get_l4_size(const struct ofpbuf *);
static inline size_t ofpbuf_l4_size(const struct ofpbuf *);
static inline const void *ofpbuf_get_tcp_payload(const struct ofpbuf *);
static inline const void *ofpbuf_get_udp_payload(const struct ofpbuf *);
static inline const void *ofpbuf_get_sctp_payload(const struct ofpbuf *);
Expand Down Expand Up @@ -247,7 +247,7 @@ static inline bool ofpbuf_equal(const struct ofpbuf *a, const struct ofpbuf *b)
memcmp(ofpbuf_data(a), ofpbuf_data(b), ofpbuf_size(a)) == 0;
}

static inline void * ofpbuf_get_l2_5(const struct ofpbuf *b)
static inline void * ofpbuf_l2_5(const struct ofpbuf *b)
{
return b->l2_5_ofs != UINT16_MAX ? (char *)b->l2 + b->l2_5_ofs : NULL;
}
Expand All @@ -257,7 +257,7 @@ static inline void ofpbuf_set_l2_5(struct ofpbuf *b, void *l2_5)
b->l2_5_ofs = l2_5 ? (char *)l2_5 - (char *)b->l2 : UINT16_MAX;
}

static inline void * ofpbuf_get_l3(const struct ofpbuf *b)
static inline void * ofpbuf_l3(const struct ofpbuf *b)
{
return b->l3_ofs != UINT16_MAX ? (char *)b->l2 + b->l3_ofs : NULL;
}
Expand All @@ -267,7 +267,7 @@ static inline void ofpbuf_set_l3(struct ofpbuf *b, void *l3)
b->l3_ofs = l3 ? (char *)l3 - (char *)b->l2 : UINT16_MAX;
}

static inline void * ofpbuf_get_l4(const struct ofpbuf *b)
static inline void * ofpbuf_l4(const struct ofpbuf *b)
{
return b->l4_ofs != UINT16_MAX ? (char *)b->l2 + b->l4_ofs : NULL;
}
Expand All @@ -277,18 +277,18 @@ static inline void ofpbuf_set_l4(struct ofpbuf *b, void *l4)
b->l4_ofs = l4 ? (char *)l4 - (char *)b->l2 : UINT16_MAX;
}

static inline size_t ofpbuf_get_l4_size(const struct ofpbuf *b)
static inline size_t ofpbuf_l4_size(const struct ofpbuf *b)
{
return b->l4_ofs != UINT16_MAX
? (const char *)ofpbuf_tail(b) - (const char *)ofpbuf_get_l4(b) : 0;
? (const char *)ofpbuf_tail(b) - (const char *)ofpbuf_l4(b) : 0;
}

static inline const void *ofpbuf_get_tcp_payload(const struct ofpbuf *b)
{
size_t l4_size = ofpbuf_get_l4_size(b);
size_t l4_size = ofpbuf_l4_size(b);

if (OVS_LIKELY(l4_size >= TCP_HEADER_LEN)) {
struct tcp_header *tcp = ofpbuf_get_l4(b);
struct tcp_header *tcp = ofpbuf_l4(b);
int tcp_len = TCP_OFFSET(tcp->tcp_ctl) * 4;

if (OVS_LIKELY(tcp_len >= TCP_HEADER_LEN && tcp_len <= l4_size)) {
Expand All @@ -300,20 +300,20 @@ static inline const void *ofpbuf_get_tcp_payload(const struct ofpbuf *b)

static inline const void *ofpbuf_get_udp_payload(const struct ofpbuf *b)
{
return OVS_LIKELY(ofpbuf_get_l4_size(b) >= UDP_HEADER_LEN)
? (const char *)ofpbuf_get_l4(b) + UDP_HEADER_LEN : NULL;
return OVS_LIKELY(ofpbuf_l4_size(b) >= UDP_HEADER_LEN)
? (const char *)ofpbuf_l4(b) + UDP_HEADER_LEN : NULL;
}

static inline const void *ofpbuf_get_sctp_payload(const struct ofpbuf *b)
{
return OVS_LIKELY(ofpbuf_get_l4_size(b) >= SCTP_HEADER_LEN)
? (const char *)ofpbuf_get_l4(b) + SCTP_HEADER_LEN : NULL;
return OVS_LIKELY(ofpbuf_l4_size(b) >= SCTP_HEADER_LEN)
? (const char *)ofpbuf_l4(b) + SCTP_HEADER_LEN : NULL;
}

static inline const void *ofpbuf_get_icmp_payload(const struct ofpbuf *b)
{
return OVS_LIKELY(ofpbuf_get_l4_size(b) >= ICMP_HEADER_LEN)
? (const char *)ofpbuf_get_l4(b) + ICMP_HEADER_LEN : NULL;
return OVS_LIKELY(ofpbuf_l4_size(b) >= ICMP_HEADER_LEN)
? (const char *)ofpbuf_l4(b) + ICMP_HEADER_LEN : NULL;
}

#ifdef DPDK_NETDEV
Expand Down
34 changes: 17 additions & 17 deletions lib/packets.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,10 @@ set_ethertype(struct ofpbuf *packet, ovs_be16 eth_type)

if (eh->eth_type == htons(ETH_TYPE_VLAN)) {
ovs_be16 *p;
char *l2_5 = ofpbuf_get_l2_5(packet);
char *l2_5 = ofpbuf_l2_5(packet);

p = ALIGNED_CAST(ovs_be16 *,
(l2_5 ? l2_5 : (char *)ofpbuf_get_l3(packet)) - 2);
(l2_5 ? l2_5 : (char *)ofpbuf_l3(packet)) - 2);
*p = eth_type;
} else {
eh->eth_type = eth_type;
Expand Down Expand Up @@ -279,7 +279,7 @@ set_mpls_lse(struct ofpbuf *packet, ovs_be32 mpls_lse)
{
/* Packet type should be MPLS to set label stack entry. */
if (is_mpls(packet)) {
struct mpls_hdr *mh = ofpbuf_get_l2_5(packet);
struct mpls_hdr *mh = ofpbuf_l2_5(packet);

/* Update mpls label stack entry. */
mh->mpls_lse = mpls_lse;
Expand Down Expand Up @@ -321,7 +321,7 @@ void
pop_mpls(struct ofpbuf *packet, ovs_be16 ethtype)
{
if (is_mpls(packet)) {
struct mpls_hdr *mh = ofpbuf_get_l2_5(packet);
struct mpls_hdr *mh = ofpbuf_l2_5(packet);
size_t len = packet->l2_5_ofs;

set_ethertype(packet, ethtype);
Expand Down Expand Up @@ -582,16 +582,16 @@ static void
packet_set_ipv4_addr(struct ofpbuf *packet,
ovs_16aligned_be32 *addr, ovs_be32 new_addr)
{
struct ip_header *nh = ofpbuf_get_l3(packet);
struct ip_header *nh = ofpbuf_l3(packet);
ovs_be32 old_addr = get_16aligned_be32(addr);
size_t l4_size = ofpbuf_get_l4_size(packet);
size_t l4_size = ofpbuf_l4_size(packet);

if (nh->ip_proto == IPPROTO_TCP && l4_size >= TCP_HEADER_LEN) {
struct tcp_header *th = ofpbuf_get_l4(packet);
struct tcp_header *th = ofpbuf_l4(packet);

th->tcp_csum = recalc_csum32(th->tcp_csum, old_addr, new_addr);
} else if (nh->ip_proto == IPPROTO_UDP && l4_size >= UDP_HEADER_LEN ) {
struct udp_header *uh = ofpbuf_get_l4(packet);
struct udp_header *uh = ofpbuf_l4(packet);

if (uh->udp_csum) {
uh->udp_csum = recalc_csum32(uh->udp_csum, old_addr, new_addr);
Expand All @@ -615,7 +615,7 @@ packet_rh_present(struct ofpbuf *packet)
int nexthdr;
size_t len;
size_t remaining;
uint8_t *data = ofpbuf_get_l3(packet);
uint8_t *data = ofpbuf_l3(packet);

remaining = packet->l4_ofs - packet->l3_ofs;

Expand Down Expand Up @@ -693,14 +693,14 @@ static void
packet_update_csum128(struct ofpbuf *packet, uint8_t proto,
ovs_16aligned_be32 addr[4], const ovs_be32 new_addr[4])
{
size_t l4_size = ofpbuf_get_l4_size(packet);
size_t l4_size = ofpbuf_l4_size(packet);

if (proto == IPPROTO_TCP && l4_size >= TCP_HEADER_LEN) {
struct tcp_header *th = ofpbuf_get_l4(packet);
struct tcp_header *th = ofpbuf_l4(packet);

th->tcp_csum = recalc_csum128(th->tcp_csum, addr, new_addr);
} else if (proto == IPPROTO_UDP && l4_size >= UDP_HEADER_LEN) {
struct udp_header *uh = ofpbuf_get_l4(packet);
struct udp_header *uh = ofpbuf_l4(packet);

if (uh->udp_csum) {
uh->udp_csum = recalc_csum128(uh->udp_csum, addr, new_addr);
Expand Down Expand Up @@ -746,7 +746,7 @@ void
packet_set_ipv4(struct ofpbuf *packet, ovs_be32 src, ovs_be32 dst,
uint8_t tos, uint8_t ttl)
{
struct ip_header *nh = ofpbuf_get_l3(packet);
struct ip_header *nh = ofpbuf_l3(packet);

if (get_16aligned_be32(&nh->ip_src) != src) {
packet_set_ipv4_addr(packet, &nh->ip_src, src);
Expand Down Expand Up @@ -782,7 +782,7 @@ packet_set_ipv6(struct ofpbuf *packet, uint8_t proto, const ovs_be32 src[4],
const ovs_be32 dst[4], uint8_t key_tc, ovs_be32 key_fl,
uint8_t key_hl)
{
struct ovs_16aligned_ip6_hdr *nh = ofpbuf_get_l3(packet);
struct ovs_16aligned_ip6_hdr *nh = ofpbuf_l3(packet);

if (memcmp(&nh->ip6_src, src, sizeof(ovs_be32[4]))) {
packet_set_ipv6_addr(packet, proto, nh->ip6_src.be32, src, true);
Expand Down Expand Up @@ -815,7 +815,7 @@ packet_set_port(ovs_be16 *port, ovs_be16 new_port, ovs_be16 *csum)
void
packet_set_tcp_port(struct ofpbuf *packet, ovs_be16 src, ovs_be16 dst)
{
struct tcp_header *th = ofpbuf_get_l4(packet);
struct tcp_header *th = ofpbuf_l4(packet);

packet_set_port(&th->tcp_src, src, &th->tcp_csum);
packet_set_port(&th->tcp_dst, dst, &th->tcp_csum);
Expand All @@ -827,7 +827,7 @@ packet_set_tcp_port(struct ofpbuf *packet, ovs_be16 src, ovs_be16 dst)
void
packet_set_udp_port(struct ofpbuf *packet, ovs_be16 src, ovs_be16 dst)
{
struct udp_header *uh = ofpbuf_get_l4(packet);
struct udp_header *uh = ofpbuf_l4(packet);

if (uh->udp_csum) {
packet_set_port(&uh->udp_src, src, &uh->udp_csum);
Expand All @@ -848,7 +848,7 @@ packet_set_udp_port(struct ofpbuf *packet, ovs_be16 src, ovs_be16 dst)
void
packet_set_sctp_port(struct ofpbuf *packet, ovs_be16 src, ovs_be16 dst)
{
struct sctp_header *sh = ofpbuf_get_l4(packet);
struct sctp_header *sh = ofpbuf_l4(packet);
ovs_be32 old_csum, old_correct_csum, new_csum;
uint16_t tp_len = ofpbuf_size(packet) - ((uint8_t*)sh - (uint8_t*)ofpbuf_data(packet));

Expand Down
2 changes: 1 addition & 1 deletion lib/pcap-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ tcp_reader_run(struct tcp_reader *r, const struct flow *flow,
|| !l7) {
return NULL;
}
tcp = ofpbuf_get_l4(packet);
tcp = ofpbuf_l4(packet);
flags = TCP_FLAGS(tcp->tcp_ctl);
l7_length = (char *) ofpbuf_tail(packet) - l7;
seq = ntohl(get_16aligned_be32(&tcp->tcp_seq));
Expand Down
Loading

0 comments on commit 6b8c377

Please sign in to comment.