diff options
author | Rafael Zalamena <rzalamena@cvs.openbsd.org> | 2016-10-11 16:37:12 +0000 |
---|---|---|
committer | Rafael Zalamena <rzalamena@cvs.openbsd.org> | 2016-10-11 16:37:12 +0000 |
commit | 3ab56faa4418c7801455c05495d428476d09cfd8 (patch) | |
tree | d2307a71445499f1b9555196cf7abcba581c0c8f /sys/net/switchofp.c | |
parent | 8001ef2f969524ed301b0621f6d58733f85c53c8 (diff) |
Small code improvements:
- use the same idiom as switchd(8) to calculate alignment;
- use oxm_value instead of doing pointer arithmetic;
- typo fix: 'recived' -> 'received';
- remove unused variable;
- use definition instead of hardcoded value;
ok reyk@
Diffstat (limited to 'sys/net/switchofp.c')
-rw-r--r-- | sys/net/switchofp.c | 69 |
1 files changed, 33 insertions, 36 deletions
diff --git a/sys/net/switchofp.c b/sys/net/switchofp.c index fe1a3601f85..a2e2fad840e 100644 --- a/sys/net/switchofp.c +++ b/sys/net/switchofp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: switchofp.c,v 1.11 2016/10/08 20:36:35 rzalamena Exp $ */ +/* $OpenBSD: switchofp.c,v 1.12 2016/10/11 16:37:11 rzalamena Exp $ */ /* * Copyright (c) 2016 Kazuya GODA <goda@openbsd.org> @@ -2083,12 +2083,14 @@ swofp_ox_match_put_start(struct ofp_match *om) int swofp_ox_match_put_end(struct ofp_match *om) { + int tsize = ntohs(om->om_length); int padding; - padding = (OFP_ALIGNMENT - ntohs(om->om_length) % OFP_ALIGNMENT) & 0x7; - memset(((caddr_t)om + ntohs(om->om_length)), 0, padding); + padding = OFP_ALIGN(tsize) - tsize; + if (padding) + memset((caddr_t)om + tsize, 0, padding); - return ntohs(om->om_length) + padding; + return tsize + padding; } int @@ -2101,7 +2103,7 @@ swofp_ox_match_put_uint32(struct ofp_match *om, uint8_t type, uint32_t val) oxm->oxm_class = htons(OFP_OXM_C_OPENFLOW_BASIC); OFP_OXM_SET_FIELD(oxm, type); oxm->oxm_length = sizeof(uint32_t); - *(uint32_t *)(oxm + 1) = htonl(val); + *(uint32_t *)oxm->oxm_value = htonl(val); om->om_length = htons(ntohs(om->om_length) + sizeof(*oxm) + sizeof(uint32_t)); @@ -2119,7 +2121,7 @@ swofp_ox_match_put_uint64(struct ofp_match *om, uint8_t type, uint64_t val) oxm->oxm_class = htons(OFP_OXM_C_OPENFLOW_BASIC); OFP_OXM_SET_FIELD(oxm, type); oxm->oxm_length = sizeof(uint64_t); - *(uint64_t *)(oxm + 1) = htobe64(val); + *(uint64_t *)oxm->oxm_value = htobe64(val); om->om_length = htons(ntohs(om->om_length) + sizeof(*oxm) + sizeof(uint64_t)); @@ -2138,7 +2140,7 @@ swofp_nx_match_put(struct ofp_match *om, uint8_t type, int len, oxm->oxm_class = htons(OFP_OXM_C_NXM_1); OFP_OXM_SET_FIELD(oxm, type); oxm->oxm_length = len; - memcpy((void *)(oxm + 1), val, len); + memcpy((void *)oxm->oxm_value, val, len); om->om_length = htons(ntohs(om->om_length) + sizeof(*oxm) + len); @@ -2151,7 +2153,7 @@ swofp_ox_set_vlan_vid(struct switch_flow_classify *swfcl, { uint16_t val; - val = *(uint16_t *)((caddr_t)oxm + sizeof(*oxm)); + val = *(uint16_t *)oxm->oxm_value; swfcl->swfcl_vlan->vlan_vid = (val & htons(EVL_VLID_MASK)); return (0); @@ -2163,7 +2165,7 @@ swofp_ox_set_uint8(struct switch_flow_classify *swfcl, { uint8_t val; - val = *(uint8_t *)((caddr_t)oxm + sizeof(*oxm)); + val = *(uint8_t *)oxm->oxm_value; switch (OFP_OXM_GET_FIELD(oxm)) { case OFP_XM_T_IP_DSCP: @@ -2212,7 +2214,7 @@ swofp_ox_set_uint16(struct switch_flow_classify *swfcl, { uint16_t val; - val = *(uint16_t *)((caddr_t)oxm + sizeof(*oxm)); + val = *(uint16_t *)oxm->oxm_value; switch (OFP_OXM_GET_FIELD(oxm)) { case OFP_XM_T_ETH_TYPE: @@ -2246,7 +2248,7 @@ swofp_ox_set_uint32(struct switch_flow_classify *swfcl, { uint32_t val; - val = *(uint32_t *)((caddr_t)oxm + sizeof(*oxm)); + val = *(uint32_t *)oxm->oxm_value; switch (OFP_OXM_GET_FIELD(oxm)) { case OFP_XM_T_IPV6_FLABEL: @@ -2263,7 +2265,7 @@ swofp_ox_set_uint64(struct switch_flow_classify *swfcl, { uint64_t val; - val = *(uint64_t *)((caddr_t)oxm + sizeof(*oxm)); + val = *(uint64_t *)oxm->oxm_value; switch (OFP_OXM_GET_FIELD(oxm)) { case OFP_XM_T_TUNNEL_ID: /* alias OFP_XM_NXMT_TUNNEL_ID */ @@ -2280,7 +2282,7 @@ swofp_ox_set_ipv6_addr(struct switch_flow_classify *swfcl, { struct in6_addr val; - memcpy(&val, ((caddr_t)oxm + sizeof(*oxm)), sizeof(val)); + memcpy(&val, oxm->oxm_value, sizeof(val)); switch (OFP_OXM_GET_FIELD(oxm)) { case OFP_XM_NXMT_TUNNEL_IPV6_SRC: @@ -2309,7 +2311,7 @@ swofp_ox_set_ipv4_addr(struct switch_flow_classify *swfcl, { uint32_t val; - val = *(uint32_t *)((caddr_t)oxm + sizeof(*oxm)); + val = *(uint32_t *)oxm->oxm_value; switch (OFP_OXM_GET_FIELD(oxm)) { case OFP_XM_NXMT_TUNNEL_IPV4_SRC: @@ -2341,7 +2343,7 @@ swofp_ox_set_ether_addr(struct switch_flow_classify *swfcl, { caddr_t eth_addr; - eth_addr = ((caddr_t)oxm + sizeof(*oxm)); + eth_addr = oxm->oxm_value; switch (OFP_OXM_GET_FIELD(oxm)) { case OFP_XM_T_ETH_SRC: @@ -2408,10 +2410,10 @@ swofp_ox_match_ipv6_addr(struct switch_flow_classify *swfcl, break; } - memcpy(&mth, ((caddr_t)oxm + sizeof(*oxm)), sizeof(mth)); + memcpy(&mth, oxm->oxm_value, sizeof(mth)); if (OFP_OXM_GET_HASMASK(oxm)) { - memcpy(&mask, ((caddr_t)oxm + sizeof(*oxm) + sizeof(mth)), + memcpy(&mask, oxm->oxm_value + sizeof(mth), sizeof(mask)); in.s6_addr32[0] &= mask.s6_addr32[0]; @@ -2475,10 +2477,10 @@ swofp_ox_match_ipv4_addr(struct switch_flow_classify *swfcl, break; } - memcpy(&mth, ((caddr_t)oxm + sizeof(*oxm)), sizeof(uint32_t)); + memcpy(&mth, oxm->oxm_value, sizeof(uint32_t)); if (OFP_OXM_GET_HASMASK(oxm)) - memcpy(&mask, ((caddr_t)oxm + sizeof(*oxm) + sizeof(uint32_t)), + memcpy(&mask, oxm->oxm_value + sizeof(uint32_t), sizeof(uint32_t)); else mask = UINT32_MAX; @@ -2496,10 +2498,10 @@ swofp_ox_match_vlan_vid(struct switch_flow_classify *swfcl, return (1); in = swfcl->swfcl_vlan->vlan_vid; - memcpy(&mth, ((caddr_t)oxm + sizeof(*oxm)), sizeof(uint16_t)); + memcpy(&mth, oxm->oxm_value, sizeof(uint16_t)); if (OFP_OXM_GET_HASMASK(oxm)) - memcpy(&mask, ((caddr_t)oxm + sizeof(*oxm) + sizeof(uint16_t)), + memcpy(&mask, oxm->oxm_value + sizeof(uint16_t), sizeof(uint16_t)); else mask = UINT16_MAX; @@ -2594,7 +2596,7 @@ swofp_ox_match_uint8(struct switch_flow_classify *swfcl, break; } - memcpy(&mth, ((caddr_t)oxm + sizeof(*oxm)), sizeof(uint8_t)); + memcpy(&mth, oxm->oxm_value, sizeof(uint8_t)); return !(in == mth); @@ -2650,7 +2652,7 @@ swofp_ox_match_uint16(struct switch_flow_classify *swfcl, break; } - memcpy(&mth , ((caddr_t)oxm + sizeof(*oxm)), sizeof(uint16_t)); + memcpy(&mth, oxm->oxm_value, sizeof(uint16_t)); return !(in == mth); } @@ -2687,10 +2689,10 @@ swofp_ox_match_uint32(struct switch_flow_classify *swfcl, break; } - memcpy(&mth, ((caddr_t)oxm + sizeof(*oxm)), sizeof(uint32_t)); + memcpy(&mth, oxm->oxm_value, sizeof(uint32_t)); if (OFP_OXM_GET_HASMASK(oxm)) - memcpy(&mask, ((caddr_t)oxm + sizeof(*oxm) + sizeof(uint32_t)), + memcpy(&mask, oxm->oxm_value + sizeof(uint32_t), sizeof(uint32_t)); else mask = nomask; @@ -2724,10 +2726,10 @@ swofp_ox_match_uint64(struct switch_flow_classify *swfcl, break; } - memcpy(&mth, ((caddr_t)oxm + sizeof(*oxm)), sizeof(uint64_t)); + memcpy(&mth, oxm->oxm_value, sizeof(uint64_t)); if (OFP_OXM_GET_HASMASK(oxm)) - memcpy(&mask, ((caddr_t)oxm + sizeof(*oxm) + sizeof(uint64_t)), + memcpy(&mask, oxm->oxm_value + sizeof(uint64_t), sizeof(uint64_t)); else mask = UINT64_MAX; @@ -2781,9 +2783,9 @@ swofp_ox_match_ether_addr(struct switch_flow_classify *swfcl, break; } - memcpy(&mth, ((caddr_t)oxm + sizeof(*oxm)), ETHER_ADDR_LEN); + memcpy(&mth, oxm->oxm_value, ETHER_ADDR_LEN); if (OFP_OXM_GET_HASMASK(oxm)) - memcpy(&mask, ((caddr_t)oxm + sizeof(*oxm) + ETHER_ADDR_LEN), + memcpy(&mask, oxm->oxm_value + ETHER_ADDR_LEN, ETHER_ADDR_LEN); else mask = UINT64_MAX; @@ -3051,7 +3053,7 @@ swofp_action_output_controller(struct switch_softc *sc, struct mbuf *m0, pin->pin_oh.oh_type = OFP_T_PACKET_IN; pin->pin_oh.oh_xid = htonl(swofs->swofs_xidnxt++); - pin->pin_buffer_id = -1; /* not buffered */ + pin->pin_buffer_id = htonl(OFP_PKTOUT_NO_BUFFER); pin->pin_table_id = swpld->swpld_table_id; pin->pin_cookie = swpld->swpld_cookie; pin->pin_reason = reason; @@ -4288,7 +4290,7 @@ swofp_input(struct switch_softc *sc, struct mbuf *m) return (EMSGSIZE); } - VDPRINTF(sc, "recived ofp message type=%s xid=%x len=%d\n", + VDPRINTF(sc, "received ofp message type=%s xid=%x len=%d\n", swofp_mtype_str(oh->oh_type), ntohl(oh->oh_xid), ntohs(oh->oh_length)); @@ -6070,12 +6072,7 @@ swofp_mp_recv_group_desc(struct switch_softc *sc, struct mbuf *m) int swofp_barrier_req(struct switch_softc *sc, struct mbuf *m) { - struct ofp_header *oh; - - oh = mtod(m, struct ofp_header *); - swofp_barrier_reply(sc, m); - return 0; } |