Browse Source

nhdp: use conn instead of socket_base

dev/timer
Martine Lenders 7 years ago committed by Martine Lenders
parent
commit
9ce1c6df05
  1. 13
      Makefile.dep
  2. 37
      sys/net/routing/nhdp/nhdp.c
  3. 1
      sys/net/routing/nhdp/nhdp.h

13
Makefile.dep

@ -6,6 +6,13 @@ ifneq (,$(filter pnet,$(USEMODULE)))
USEMODULE += vtimer
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
@ -294,12 +301,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

37
sys/net/routing/nhdp/nhdp.c

@ -18,6 +18,7 @@
* @}
*/
#include "conn/udp.h"
#include "msg.h"
#include "netapi.h"
#include "net/gnrc/netif.h"
@ -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];
@ -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;
@ -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,
@ -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 */
@ -316,7 +314,7 @@ static void *_nhdp_receiver(void *arg __attribute__((unused)))
}
}
socket_base_close(sock_rcv);
gnrc_udp_close(&conn);
return 0;
}
@ -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
sys/net/routing/nhdp/nhdp.h

@ -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"

Loading…
Cancel
Save