Skip to content

Commit

Permalink
Merge pull request #3876 from authmillenon/nhdp/enh/use-conn
Browse files Browse the repository at this point in the history
nhdp: use conn instead of socket_base
  • Loading branch information
miri64 committed Sep 23, 2015
2 parents ed45124 + 9ce1c6d commit 320aa47
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 25 deletions.
13 changes: 7 additions & 6 deletions Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ ifneq (,$(filter libcoap,$(USEPKG)))
USEMODULE += posix_sockets
endif

ifneq (,$(filter nhdp,$(USEMODULE)))
USEMODULE += conn_udp
USEMODULE += vtimer
USEMODULE += oonf_common
USEMODULE += oonf_rfc5444
endif

ifneq (,$(filter gnrc_%,$(filter-out gnrc_netapi gnrc_netreg gnrc_netif% gnrc_pktbuf,$(USEMODULE))))
USEMODULE += gnrc
endif
Expand Down Expand Up @@ -295,12 +302,6 @@ ifneq (,$(filter libfixmath-unittests,$(USEMODULE)))
USEPKG += libfixmath
endif

ifneq (,$(filter nhdp,$(USEMODULE)))
USEMODULE += vtimer
USEMODULE += oonf_common
USEMODULE += oonf_rfc5444
endif

ifneq (,$(filter fib,$(USEMODULE)))
USEMODULE += universal_address
USEMODULE += xtimer
Expand Down
37 changes: 19 additions & 18 deletions sys/net/routing/nhdp/nhdp.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* @}
*/

#include "conn/udp.h"
#include "msg.h"
#include "netapi.h"
#include "net/gnrc/netif.h"
Expand All @@ -35,6 +36,10 @@
#include "nhdp_writer.h"
#include "nhdp_reader.h"

#ifndef MODULE_CONN_UDP
#error "nhdp needs a conn_udp implementation to work"
#endif

char nhdp_stack[NHDP_STACK_SIZE];
char nhdp_rcv_stack[NHDP_STACK_SIZE];

Expand All @@ -44,8 +49,7 @@ static kernel_pid_t nhdp_rcv_pid = KERNEL_PID_UNDEF;
static kernel_pid_t helper_pid = KERNEL_PID_UNDEF;
static nhdp_if_entry_t nhdp_if_table[GNRC_NETIF_NUMOF];
static mutex_t send_rcv_mutex = MUTEX_INIT;
static sockaddr6_t sa_bcast;
static int sock_rcv;
static conn_udp_t conn;

#if (NHDP_METRIC_NEEDS_TIMER)
static vtimer_t metric_timer;
Expand Down Expand Up @@ -85,12 +89,6 @@ kernel_pid_t nhdp_start(void)
{
if (nhdp_pid == KERNEL_PID_UNDEF) {
/* Init destination address for NHDP's packets */
sa_bcast.sin6_family = AF_INET6;
sa_bcast.sin6_port = HTONS(MANET_PORT);
ipv6_addr_set_all_nodes_addr(&sa_bcast.sin6_addr);

/* Configure sending/receiving UDP socket */
sock_rcv = socket_base_socket(AF_INET6, SOCK_DGRAM, IPPROTO_UDP);

/* Start the NHDP thread */
nhdp_pid = thread_create(nhdp_stack, sizeof(nhdp_stack), THREAD_PRIORITY_MAIN - 1,
Expand Down Expand Up @@ -293,20 +291,20 @@ static void *_nhdp_receiver(void *arg __attribute__((unused)))
msg_init_queue(msg_q, NHDP_MSG_QUEUE_SIZE);

/* Configure socket address for the manet port 269 */
sockaddr6_t sa_rcv = {.sin6_family = AF_INET6,
.sin6_port = HTONS(MANET_PORT)
};
ipv6_addr_t unspec = IPV6_ADDR_UNSPECIFIED;

/* Bind UDP socket to socket address */
if (socket_base_bind(sock_rcv, &sa_rcv, sizeof(sa_rcv)) == -1) {
/* Failed binding the socket */
socket_base_close(sock_rcv);
if (conn_udp_create(&conn, &unspec, sizeof(unspec), AF_INET6, MANET_PORT) == -1) {
/* Failed creating the connection */
return 0;
}

while (1) {
int32_t rcv_size = socket_base_recvfrom(sock_rcv, (void *)nhdp_rcv_buf,
NHDP_MAX_RFC5444_PACKET_SZ, 0, &sa_rcv, &fromlen);
ipv6_addr_t rcv_addr;
uint16_t rcv_port;
int32_t rcv_size = conn_udp_recvfrom(&conn, (void *)nhdp_rcv_buf,
NHDP_MAX_RFC5444_PACKET_SZ, &rcv_addr,
sizeof(rcv_addr), &rcv_port);

if (rcv_size > 0) {
/* Packet received, let the reader handle it */
Expand All @@ -316,7 +314,7 @@ static void *_nhdp_receiver(void *arg __attribute__((unused)))
}
}

socket_base_close(sock_rcv);
gnrc_udp_close(&conn);
return 0;
}

Expand All @@ -328,5 +326,8 @@ static void write_packet(struct rfc5444_writer *wr __attribute__((unused)),
struct rfc5444_writer_target *iface __attribute__((unused)),
void *buffer, size_t length)
{
socket_base_sendto(sock_rcv, buffer, length, 0, &sa_bcast, sizeof(sa_bcast));
ipv6_addr_t src, dst = IPV6_ADDR_ALL_NODES_LINK_LOCAL;
uint16_t sport, dport = MANET_PORT;
conn_udp_getlocaladdr(&conn, &src, &sport);
conn_udp_sendto(buffer, length, &src, sizeof(src), &dst, sizeof(dst), AF_INET, sport, dport);
}
1 change: 0 additions & 1 deletion sys/net/routing/nhdp/nhdp.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

#include "timex.h"
#include "kernel_types.h"
#include "socket_base/socket.h"

#include "nhdp_metric.h"
#include "rfc5444/rfc5444_writer.h"
Expand Down

0 comments on commit 320aa47

Please sign in to comment.