Browse Source

gnrc ipv6 hdr: remove len params from hdr_build

pr/gpio
Oleg Hahm 7 years ago
parent
commit
360413a033
  1. 2
      examples/gnrc_networking/udp.c
  2. 9
      sys/include/net/gnrc/ipv6/hdr.h
  3. 2
      sys/net/gnrc/application_layer/tftp/gnrc_tftp.c
  4. 3
      sys/net/gnrc/application_layer/zep/gnrc_zep.c
  5. 2
      sys/net/gnrc/conn/ip/gnrc_conn_ip.c
  6. 2
      sys/net/gnrc/conn/udp/gnrc_conn_udp.c
  7. 2
      sys/net/gnrc/netreg/gnrc_netreg.c
  8. 6
      sys/net/gnrc/network_layer/icmpv6/echo/gnrc_icmpv6_echo.c
  9. 22
      sys/net/gnrc/network_layer/ipv6/hdr/gnrc_ipv6_hdr.c
  10. 4
      sys/net/gnrc/network_layer/ndp/internal/gnrc_ndp_internal.c
  11. 3
      sys/net/gnrc/routing/rpl/gnrc_rpl_control_messages.c
  12. 40
      tests/unittests/tests-gnrc_ipv6_hdr/tests-gnrc_ipv6_hdr.c

2
examples/gnrc_networking/udp.c

@ -65,7 +65,7 @@ static void send(char *addr_str, char *port_str, char *data, unsigned int num,
return;
}
/* allocate IPv6 header */
ip = gnrc_ipv6_hdr_build(udp, NULL, 0, (uint8_t *)&addr, sizeof(addr));
ip = gnrc_ipv6_hdr_build(udp, NULL, (uint8_t *)&addr);
if (ip == NULL) {
puts("Error: unable to allocate IPv6 header");
gnrc_pktbuf_release(udp);

9
sys/include/net/gnrc/ipv6/hdr.h

@ -37,19 +37,14 @@ extern "C" {
* @param[in] payload Payload for the packet.
* @param[in] src Source address for the header. Can be NULL if not
* known or required.
* @param[in] src_len Length of @p src. Can be 0 if not known or required or
* must be `sizeof(ipv6_addr_t)`.
* @param[in] dst Destination address for the header. Can be NULL if not
* known or required.
* @param[in] dst_len Length of @p dst. Can be 0 if not known or required or
* must be `sizeof(ipv6_addr_t)`.
*
* @return The an IPv6 header in packet buffer on success.
* @return NULL on error.
*/
gnrc_pktsnip_t *gnrc_ipv6_hdr_build(gnrc_pktsnip_t *payload,
uint8_t *src, uint8_t src_len,
uint8_t *dst, uint8_t dst_len);
gnrc_pktsnip_t *gnrc_ipv6_hdr_build(gnrc_pktsnip_t *payload, uint8_t *src,
uint8_t *dst);
#ifdef __cplusplus
}

2
sys/net/gnrc/application_layer/tftp/gnrc_tftp.c

@ -971,7 +971,7 @@ tftp_state _tftp_send(gnrc_pktsnip_t *buf, tftp_context_t *ctxt, size_t len)
}
/* allocate IPv6 header */
ip = gnrc_ipv6_hdr_build(udp, NULL, 0, ctxt->peer.u8, sizeof(ipv6_addr_t));
ip = gnrc_ipv6_hdr_build(udp, NULL, ctxt->peer.u8);
if (ip == NULL) {
DEBUG("tftp: error unable to allocate IPv6 header");
gnrc_pktbuf_release(udp);

3
sys/net/gnrc/application_layer/zep/gnrc_zep.c

@ -241,8 +241,7 @@ static int _send(gnrc_netdev_t *netdev, gnrc_pktsnip_t *pkt)
new_pkt = hdr;
hdr = gnrc_ipv6_hdr_build(new_pkt, NULL, 0, (uint8_t *) &(dev->dst),
sizeof(ipv6_addr_t));
hdr = gnrc_ipv6_hdr_build(new_pkt, NULL, (uint8_t *) &(dev->dst));
if (hdr == NULL) {
DEBUG("zep: could not allocate IPv6 header in pktbuf\n");

2
sys/net/gnrc/conn/ip/gnrc_conn_ip.c

@ -99,7 +99,7 @@ int conn_ip_sendto(const void *data, size_t len, const void *src, size_t src_len
return -EINVAL;
}
/* addr will only be copied */
hdr = gnrc_ipv6_hdr_build(pkt, (uint8_t *)src, src_len, (uint8_t *)dst, dst_len);
hdr = gnrc_ipv6_hdr_build(pkt, (uint8_t *)src, (uint8_t *)dst);
if (hdr == NULL) {
gnrc_pktbuf_release(pkt);
return -ENOMEM;

2
sys/net/gnrc/conn/udp/gnrc_conn_udp.c

@ -111,7 +111,7 @@ int conn_udp_sendto(const void *data, size_t len, const void *src, size_t src_le
return -EINVAL;
}
/* addr will only be copied */
hdr = gnrc_ipv6_hdr_build(pkt, (uint8_t *)src, src_len, (uint8_t *)dst, dst_len);
hdr = gnrc_ipv6_hdr_build(pkt, (uint8_t *)src, (uint8_t *)dst);
if (hdr == NULL) {
gnrc_pktbuf_release(pkt);
return -ENOMEM;

2
sys/net/gnrc/netreg/gnrc_netreg.c

@ -143,7 +143,7 @@ gnrc_pktsnip_t *gnrc_netreg_hdr_build(gnrc_nettype_t type, gnrc_pktsnip_t *paylo
#ifdef MODULE_GNRC_IPV6
case GNRC_NETTYPE_IPV6:
return gnrc_ipv6_hdr_build(payload, src, src_len, dst, dst_len);
return gnrc_ipv6_hdr_build(payload, src, dst);
#endif
#ifdef MODULE_GNRC_TCP

6
sys/net/gnrc/network_layer/icmpv6/echo/gnrc_icmpv6_echo.c

@ -84,13 +84,11 @@ void gnrc_icmpv6_echo_req_handle(kernel_pid_t iface, ipv6_hdr_t *ipv6_hdr,
}
if (ipv6_addr_is_multicast(&ipv6_hdr->dst)) {
hdr = gnrc_ipv6_hdr_build(pkt, NULL, 0, (uint8_t *)&ipv6_hdr->src,
sizeof(ipv6_addr_t));
hdr = gnrc_ipv6_hdr_build(pkt, NULL, (uint8_t *)&ipv6_hdr->src);
}
else {
hdr = gnrc_ipv6_hdr_build(pkt, (uint8_t *)&ipv6_hdr->dst,
sizeof(ipv6_addr_t), (uint8_t *)&ipv6_hdr->src,
sizeof(ipv6_addr_t));
(uint8_t *)&ipv6_hdr->src);
}
if (hdr == NULL) {

22
sys/net/gnrc/network_layer/ipv6/hdr/gnrc_ipv6_hdr.c

@ -32,20 +32,12 @@ static char addr_str[IPV6_ADDR_MAX_STR_LEN];
#define HDR_NETTYPE (GNRC_NETTYPE_UNDEF)
#endif
gnrc_pktsnip_t *gnrc_ipv6_hdr_build(gnrc_pktsnip_t *payload,
uint8_t *src, uint8_t src_len,
uint8_t *dst, uint8_t dst_len)
gnrc_pktsnip_t *gnrc_ipv6_hdr_build(gnrc_pktsnip_t *payload, uint8_t *src,
uint8_t *dst)
{
gnrc_pktsnip_t *ipv6;
ipv6_hdr_t *hdr;
if (((src_len != 0) && (src_len != sizeof(ipv6_addr_t))) ||
((dst_len != 0) && (dst_len != sizeof(ipv6_addr_t)))) {
DEBUG("ipv6_hdr: Address length was not 0 or %zu byte.\n",
sizeof(ipv6_addr_t));
return NULL;
}
ipv6 = gnrc_pktbuf_add(payload, NULL, sizeof(ipv6_hdr_t), HDR_NETTYPE);
if (ipv6 == NULL) {
@ -55,28 +47,26 @@ gnrc_pktsnip_t *gnrc_ipv6_hdr_build(gnrc_pktsnip_t *payload,
hdr = (ipv6_hdr_t *)ipv6->data;
if ((src != NULL) && (src_len != 0)) {
if (src != NULL) {
#ifdef MODULE_IPV6_ADDR
DEBUG("ipv6_hdr: set packet source to %s\n",
ipv6_addr_to_str(addr_str, (ipv6_addr_t *)src,
sizeof(addr_str)));
#endif
memcpy(&hdr->src, src, src_len);
memcpy(&hdr->src, src, sizeof(ipv6_addr_t));
}
else {
DEBUG("ipv6_hdr: set packet source to ::\n");
ipv6_addr_set_unspecified(&hdr->src);
}
memset(&hdr->dst + dst_len, 0, sizeof(ipv6_addr_t) - dst_len);
if ((dst != NULL) && (dst_len != 0)) {
if (dst != NULL) {
#ifdef MODULE_IPV6_ADDR
DEBUG("ipv6_hdr: set packet destination to %s\n",
ipv6_addr_to_str(addr_str, (ipv6_addr_t *)dst,
sizeof(addr_str)));
#endif
memcpy(&hdr->dst, dst, dst_len);
memcpy(&hdr->dst, dst, sizeof(ipv6_addr_t));
}
else {
DEBUG("ipv6_hdr: set packet destination to ::1\n");

4
sys/net/gnrc/network_layer/ndp/internal/gnrc_ndp_internal.c

@ -837,8 +837,8 @@ static gnrc_pktsnip_t *_build_headers(kernel_pid_t iface, gnrc_pktsnip_t *payloa
ipv6_addr_t *dst, ipv6_addr_t *src)
{
gnrc_pktsnip_t *l2hdr;
gnrc_pktsnip_t *iphdr = gnrc_ipv6_hdr_build(payload, (uint8_t *)src, sizeof(ipv6_addr_t),
(uint8_t *)dst, sizeof(ipv6_addr_t));
gnrc_pktsnip_t *iphdr = gnrc_ipv6_hdr_build(payload, (uint8_t *)src,
(uint8_t *)dst);
if (iphdr == NULL) {
DEBUG("ndp internal: error allocating IPv6 header.\n");
return NULL;

3
sys/net/gnrc/routing/rpl/gnrc_rpl_control_messages.c

@ -77,8 +77,7 @@ void gnrc_rpl_send(gnrc_pktsnip_t *pkt, kernel_pid_t iface, ipv6_addr_t *src, ip
dst = (ipv6_addr_t *) &ipv6_addr_all_rpl_nodes;
}
hdr = gnrc_ipv6_hdr_build(pkt, (uint8_t *)src, sizeof(ipv6_addr_t), (uint8_t *)dst,
sizeof(ipv6_addr_t));
hdr = gnrc_ipv6_hdr_build(pkt, (uint8_t *)src, (uint8_t *)dst);
if (hdr == NULL) {
DEBUG("RPL: Send - no space left in packet buffer\n");

40
tests/unittests/tests-gnrc_ipv6_hdr/tests-gnrc_ipv6_hdr.c

@ -35,32 +35,6 @@
} \
}
static void test_gnrc_ipv6_hdr_build__wrong_src_len(void)
{
ipv6_addr_t src = DEFAULT_TEST_SRC;
ipv6_addr_t dst = DEFAULT_TEST_DST;
gnrc_pktbuf_init();
TEST_ASSERT_NULL(gnrc_ipv6_hdr_build(NULL, (uint8_t *)&src,
sizeof(ipv6_addr_t) + TEST_UINT8,
(uint8_t *)&dst,
sizeof(ipv6_addr_t)));
TEST_ASSERT(gnrc_pktbuf_is_empty());
}
static void test_gnrc_ipv6_hdr_build__wrong_dst_len(void)
{
ipv6_addr_t src = DEFAULT_TEST_SRC;
ipv6_addr_t dst = DEFAULT_TEST_DST;
gnrc_pktbuf_init();
TEST_ASSERT_NULL(gnrc_ipv6_hdr_build(NULL, (uint8_t *)&src,
sizeof(ipv6_addr_t),
(uint8_t *)&dst,
sizeof(ipv6_addr_t) + TEST_UINT8));
TEST_ASSERT(gnrc_pktbuf_is_empty());
}
static void test_gnrc_ipv6_hdr_build__src_NULL(void)
{
ipv6_addr_t dst = DEFAULT_TEST_DST;
@ -68,8 +42,7 @@ static void test_gnrc_ipv6_hdr_build__src_NULL(void)
ipv6_hdr_t *hdr;
gnrc_pktbuf_init();
TEST_ASSERT_NOT_NULL((pkt = gnrc_ipv6_hdr_build(NULL, NULL, 0, (uint8_t *)&dst,
sizeof(ipv6_addr_t))));
TEST_ASSERT_NOT_NULL(pkt = gnrc_ipv6_hdr_build(NULL, NULL, (uint8_t *)&dst));
hdr = pkt->data;
TEST_ASSERT_NOT_NULL(hdr);
TEST_ASSERT(ipv6_hdr_is(hdr));
@ -88,9 +61,7 @@ static void test_gnrc_ipv6_hdr_build__dst_NULL(void)
ipv6_hdr_t *hdr;
gnrc_pktbuf_init();
TEST_ASSERT_NOT_NULL((pkt = gnrc_ipv6_hdr_build(NULL, (uint8_t *)&src,
sizeof(ipv6_addr_t),
NULL, 0)));
TEST_ASSERT_NOT_NULL(pkt = gnrc_ipv6_hdr_build(NULL, (uint8_t *)&src, NULL));
hdr = pkt->data;
TEST_ASSERT_NOT_NULL(hdr);
TEST_ASSERT(ipv6_hdr_is(hdr));
@ -110,10 +81,7 @@ static void test_gnrc_ipv6_hdr_build__complete(void)
ipv6_hdr_t *hdr;
gnrc_pktbuf_init();
TEST_ASSERT_NOT_NULL((pkt = gnrc_ipv6_hdr_build(NULL, (uint8_t *)&src,
sizeof(ipv6_addr_t),
(uint8_t *)&dst,
sizeof(ipv6_addr_t))));
TEST_ASSERT_NOT_NULL(pkt = gnrc_ipv6_hdr_build(NULL, (uint8_t *)&src, (uint8_t *)&dst));
hdr = pkt->data;
TEST_ASSERT_NOT_NULL(hdr);
TEST_ASSERT(ipv6_hdr_is(hdr));
@ -129,8 +97,6 @@ static void test_gnrc_ipv6_hdr_build__complete(void)
Test *tests_gnrc_ipv6_hdr_tests(void)
{
EMB_UNIT_TESTFIXTURES(fixtures) {
new_TestFixture(test_gnrc_ipv6_hdr_build__wrong_src_len),
new_TestFixture(test_gnrc_ipv6_hdr_build__wrong_dst_len),
new_TestFixture(test_gnrc_ipv6_hdr_build__src_NULL),
new_TestFixture(test_gnrc_ipv6_hdr_build__dst_NULL),
new_TestFixture(test_gnrc_ipv6_hdr_build__complete),

Loading…
Cancel
Save