} __attribute__((packed)) arprefresh_buf;
static int arprefresh_sockfd = -1;
-static const int arprefresh_portnum = 698;
static struct olsr_cookie_info *arp_event_timer_cookie;
/**
{ 0x30, 0, 0, 0x00000014 },
{ 0x15, 0, 11, 0x00000011 },
{ 0x28, 0, 0, 0x00000038 },
- { 0x15, 8, 9, arprefresh_portnum },
+ { 0x15, 8, 9, olsr_cnf->olsr_port },
{ 0x15, 0, 8, 0x00000800 },
{ 0x30, 0, 0, 0x00000017 },
{ 0x15, 0, 6, 0x00000011 },
{ 0x45, 4, 0, 0x00001fff },
{ 0xb1, 0, 0, 0x0000000e },
{ 0x48, 0, 0, 0x00000010 },
- { 0x15, 0, 1, arprefresh_portnum },
+ { 0x15, 0, 1, olsr_cnf->olsr_port },
{ 0x6, 0, 0, sizeof(arprefresh_buf) },
{ 0x6, 0, 0, 0x00000000 }
};
assert(ipPacket != NULL);
- /* OLSR packets are UDP - port 698
+ /* OLSR packets are UDP - port 698 (as default)
* OLSR-BMF packets are UDP - port 50698
* OLSR-Autodetect probe packets are UDP - port 51698 */
udpHeader = (struct udphdr*) (ipPacket + ipHeaderLen);
destPort = ntohs(udpHeader->dest);
- if (destPort == OLSRPORT || destPort == BMF_ENCAP_PORT || destPort == 51698)
+ if (destPort == olsr_cnf->olsr_port || destPort == BMF_ENCAP_PORT || destPort == 51698)
/* TODO: #define for 51698 */
{
return 1;
ip_id = (u_int16_t) (arc4random() & 0xffff);
}
- udp_tag = libnet_build_udp(698, /* src port */
- 698, /* dest port */
+ udp_tag = libnet_build_udp(olsr_cnf->olsr_port, /* src port */
+ olsr_cnf->olsr_port, /* dest port */
LIBNET_UDP_H + len, /* length */
0, /* checksum */
buf, /* payload */
memset(&sin4, 0, sizeof(sin4));
sin4.sin_family = AF_INET;
- sin4.sin_port = htons(OLSRPORT);
+ sin4.sin_port = htons(olsr_cnf->olsr_port);
assert(sin4.sin_addr.s_addr == INADDR_ANY);
if (bind(sock, (struct sockaddr *)&sin4, sizeof(sin4)) < 0) {
perror("bind");
memset(&sin6, 0, sizeof(sin6));
sin6.sin6_family = AF_INET6;
- sin6.sin6_port = htons(OLSRPORT);
+ sin6.sin6_port = htons(olsr_cnf->olsr_port);
assert(0 == memcmp(&sin6.sin6_addr, &in6addr_any, sizeof(sin6.sin6_addr))); /* == IN6ADDR_ANY_INIT */
if (bind(sock, (struct sockaddr *)&sin6, sizeof(sin6)) < 0) {
perror("bind");
/* Copy sin */
dstaddr.sin4 = ifp->int_broadaddr;
if (dstaddr.sin4.sin_port == 0) {
- dstaddr.sin4.sin_port = htons(OLSRPORT);
+ dstaddr.sin4.sin_port = htons(olsr_cnf->olsr_port);
}
dstaddr_size = sizeof(dstaddr.sin4);
} else {
}
rcfg->fixed_origaddr = true;
break;
+ case '1': /* port (i) */
+ {
+ int arg = -1;
+ sscanf(argstr, "%d", &arg);
+ if (0 <= arg && arg < (1 << (8 * sizeof(rcfg->olsr_port))))
+ rcfg->olsr_port = arg;
+ PARSER_DEBUG_PRINTF("OLSR port: %d\n", rcfg->olsr_port);
+ }
+ break;
default:
sprintf(rmsg, "Unknown arg in line %d.\n", line);
return CFG_ERROR;
{"Willingness", required_argument, 0, 'w'}, /* (i) */
{"RouterId", required_argument, 0, 'o'}, /* (ip) */
{"SourceIpMode", required_argument, 0, 's'}, /* (yes/no) */
+ {"Port", required_argument, 0, '1'}, /* (i) */
{"UseHysteresis", required_argument, 0, 0 }, /* ignored */
{"HystScaling", required_argument, 0, 0 }, /* ignored */
return -1;
}
+ /* check OLSR port */
+ if (cfg->olsr_port == 0) {
+ fprintf(stderr, "0 is not a valid UDP port\n");
+ return -1;
+ }
+
if (in == NULL) {
fprintf(stderr, "No interfaces configured!\n");
return -1;
cfg->lq_dlimit = DEF_LQ_DIJK_LIMIT;
assert(cfg->willingness == 0);
+ cfg->olsr_port = 698;
+
assert(cfg->system_tick_divider == 0);
assert(0 == memcmp(&all_zero, &cfg->router_id, sizeof(cfg->router_id)));
assert(0 == cfg->source_ip_mode);
uint8_t lq_dlimit; /* Dijkstra Calculation limit */
uint8_t willingness; /* Manual Configured Willingness value */
+ uint16_t olsr_port; /* port number used for OLSR packages */
/*
* Someone has added global variables to the config struct.
* Because this saves binary link info we keep it that way.
#include <string.h>
-/* Port for OLSR to use */
-
-#define OLSRPORT 698
-
/* Default IPv6 multicast addresses */
#define OLSR_IPV6_MCAST_SITE_LOCAL "ff05::15"
ifp->int6_multaddr.sin6_family = AF_INET6;
ifp->int6_multaddr.sin6_flowinfo = htonl(0);
ifp->int6_multaddr.sin6_scope_id = if_nametoindex(ifr.ifr_name);
- ifp->int6_multaddr.sin6_port = htons(OLSRPORT);
+ ifp->int6_multaddr.sin6_port = htons(olsr_cnf->olsr_port);
ifp->int6_multaddr.sin6_addr = iface->cnf->ipv6_addrtype == OLSR_IP6T_SITELOCAL
? iface->cnf->ipv6_multi_site.v6
: iface->cnf->ipv6_multi_glbl.v6;