diff options
Diffstat (limited to 'nhrp')
-rw-r--r-- | nhrp/admin.c | 10 | ||||
-rw-r--r-- | nhrp/afnum.h | 10 | ||||
-rw-r--r-- | nhrp/list.h | 10 | ||||
-rw-r--r-- | nhrp/nhrp_address.c | 10 | ||||
-rw-r--r-- | nhrp/nhrp_address.h | 10 | ||||
-rw-r--r-- | nhrp/nhrp_common.h | 10 | ||||
-rw-r--r-- | nhrp/nhrp_defines.h | 10 | ||||
-rw-r--r-- | nhrp/nhrp_interface.c | 10 | ||||
-rw-r--r-- | nhrp/nhrp_interface.h | 10 | ||||
-rw-r--r-- | nhrp/nhrp_packet.c | 21 | ||||
-rw-r--r-- | nhrp/nhrp_packet.h | 10 | ||||
-rw-r--r-- | nhrp/nhrp_peer.c | 50 | ||||
-rw-r--r-- | nhrp/nhrp_peer.h | 10 | ||||
-rw-r--r-- | nhrp/nhrp_protocol.h | 10 | ||||
-rw-r--r-- | nhrp/nhrp_server.c | 10 | ||||
-rw-r--r-- | nhrp/opennhrp.c | 10 | ||||
-rw-r--r-- | nhrp/opennhrpctl.c | 10 | ||||
-rw-r--r-- | nhrp/sysdep_netlink.c | 10 | ||||
-rw-r--r-- | nhrp/sysdep_pfpacket.c | 52 | ||||
-rw-r--r-- | nhrp/sysdep_syslog.c | 10 |
20 files changed, 130 insertions, 163 deletions
diff --git a/nhrp/admin.c b/nhrp/admin.c index d89fa87..6e0a5e2 100644 --- a/nhrp/admin.c +++ b/nhrp/admin.c @@ -1,13 +1,9 @@ /* admin.c - OpenNHRP administrative interface implementation * - * Copyright (C) 2007-2009 Timo Teräs <timo.teras@iki.fi> - * All rights reserved. + * Copyright (c) 2007-2012 Timo Teräs <timo.teras@iki.fi> * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 or later as - * published by the Free Software Foundation. - * - * See http://www.gnu.org/ for details. + * This software is licensed under the MIT License. + * See MIT-LICENSE.txt for additional details. */ #include <ctype.h> diff --git a/nhrp/afnum.h b/nhrp/afnum.h index 2dc3d68..0505c5b 100644 --- a/nhrp/afnum.h +++ b/nhrp/afnum.h @@ -1,14 +1,10 @@ /* afnum.h - RFC 1700 Address Family Number and * ethernet protocol number definitions * - * Copyright (C) 2007 Timo Teräs <timo.teras@iki.fi> - * All rights reserved. + * Copyright (c) 2007-2012 Timo Teräs <timo.teras@iki.fi> * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 or later as - * published by the Free Software Foundation. - * - * See http://www.gnu.org/ for details. + * This software is licensed under the MIT License. + * See MIT-LICENSE.txt for additional details. */ #ifndef AFNUM_H diff --git a/nhrp/list.h b/nhrp/list.h index 4387970..caa22e4 100644 --- a/nhrp/list.h +++ b/nhrp/list.h @@ -1,13 +1,9 @@ /* list.h - Single and double linked list macros * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 or later as - * published by the Free Software Foundation. + * Copyright (c) 2007-2012 Timo Teräs <timo.teras@iki.fi> * - * See http://www.gnu.org/ for details. - * - * This is more or less based on the code in the linux kernel. There are - * minor differences and this is only a subset of the kernel version. + * This software is licensed under the MIT License. + * See MIT-LICENSE.txt for additional details. */ #ifndef LIST_H diff --git a/nhrp/nhrp_address.c b/nhrp/nhrp_address.c index 13164e1..808edf1 100644 --- a/nhrp/nhrp_address.c +++ b/nhrp/nhrp_address.c @@ -1,13 +1,9 @@ /* nhrp_address.c - NHRP address conversion functions * - * Copyright (C) 2007-2009 Timo Teräs <timo.teras@iki.fi> - * All rights reserved. + * Copyright (c) 2007-2012 Timo Teräs <timo.teras@iki.fi> * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 or later as - * published by the Free Software Foundation. - * - * See http://www.gnu.org/ for details. + * This software is licensed under the MIT License. + * See MIT-LICENSE.txt for additional details. */ #include <stdio.h> diff --git a/nhrp/nhrp_address.h b/nhrp/nhrp_address.h index e479631..8ec2b41 100644 --- a/nhrp/nhrp_address.h +++ b/nhrp/nhrp_address.h @@ -1,13 +1,9 @@ /* nhrp_address.h - NHRP address structures and helpers * - * Copyright (C) 2007 Timo Teräs <timo.teras@iki.fi> - * All rights reserved. + * Copyright (c) 2007-2012 Timo Teräs <timo.teras@iki.fi> * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 or later as - * published by the Free Software Foundation. - * - * See http://www.gnu.org/ for details. + * This software is licensed under the MIT License. + * See MIT-LICENSE.txt for additional details. */ #ifndef NHRP_ADDRESS_H diff --git a/nhrp/nhrp_common.h b/nhrp/nhrp_common.h index 6730e74..9422382 100644 --- a/nhrp/nhrp_common.h +++ b/nhrp/nhrp_common.h @@ -1,13 +1,9 @@ /* nhrp_common.h - Generic helper functions * - * Copyright (C) 2007-2009 Timo Teräs <timo.teras@iki.fi> - * All rights reserved. + * Copyright (c) 2007-2012 Timo Teräs <timo.teras@iki.fi> * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 or later as - * published by the Free Software Foundation. - * - * See http://www.gnu.org/ for details. + * This software is licensed under the MIT License. + * See MIT-LICENSE.txt for additional details. */ #ifndef NHRP_COMMON_H diff --git a/nhrp/nhrp_defines.h b/nhrp/nhrp_defines.h index 2812a13..37e4715 100644 --- a/nhrp/nhrp_defines.h +++ b/nhrp/nhrp_defines.h @@ -1,13 +1,9 @@ /* nhrp_defines.h - NHRP definitions * - * Copyright (C) 2007 Timo Teräs <timo.teras@iki.fi> - * All rights reserved. + * Copyright (c) 2007-2012 Timo Teräs <timo.teras@iki.fi> * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 or later as - * published by the Free Software Foundation. - * - * See http://www.gnu.org/ for details. + * This software is licensed under the MIT License. + * See MIT-LICENSE.txt for additional details. */ #ifndef NHRP_DEFINES_H diff --git a/nhrp/nhrp_interface.c b/nhrp/nhrp_interface.c index 05f0e80..f07e5d4 100644 --- a/nhrp/nhrp_interface.c +++ b/nhrp/nhrp_interface.c @@ -1,13 +1,9 @@ /* nhrp_interface.c - NHRP configuration per interface * - * Copyright (C) 2007 Timo Teräs <timo.teras@iki.fi> - * All rights reserved. + * Copyright (c) 2007-2012 Timo Teräs <timo.teras@iki.fi> * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 or later as - * published by the Free Software Foundation. - * - * See http://www.gnu.org/ for details. + * This software is licensed under the MIT License. + * See MIT-LICENSE.txt for additional details. */ #include <stdio.h> diff --git a/nhrp/nhrp_interface.h b/nhrp/nhrp_interface.h index 8e3e8df..5fade69 100644 --- a/nhrp/nhrp_interface.h +++ b/nhrp/nhrp_interface.h @@ -1,13 +1,9 @@ /* nhrp_interface.h - NHRP configuration per interface definitions * - * Copyright (C) 2007 Timo Teräs <timo.teras@iki.fi> - * All rights reserved. + * Copyright (c) 2007-2012 Timo Teräs <timo.teras@iki.fi> * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 or later as - * published by the Free Software Foundation. - * - * See http://www.gnu.org/ for details. + * This software is licensed under the MIT License. + * See MIT-LICENSE.txt for additional details. */ #ifndef NHRP_INTERFACE_H diff --git a/nhrp/nhrp_packet.c b/nhrp/nhrp_packet.c index f46b481..4edf392 100644 --- a/nhrp/nhrp_packet.c +++ b/nhrp/nhrp_packet.c @@ -1,13 +1,9 @@ /* nhrp_packet.c - NHRP packet marshalling and tranceiving * - * Copyright (C) 2007-2009 Timo Teräs <timo.teras@iki.fi> - * All rights reserved. + * Copyright (c) 2007-2012 Timo Teräs <timo.teras@iki.fi> * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 or later as - * published by the Free Software Foundation. - * - * See http://www.gnu.org/ for details. + * This software is licensed under the MIT License. + * See MIT-LICENSE.txt for additional details. */ #include <malloc.h> @@ -979,7 +975,7 @@ int nhrp_packet_route(struct nhrp_packet *packet) struct nhrp_payload *payload; struct nhrp_peer *peer; char tmp[64]; - int r; + int i, r; if (packet->dst_iface == NULL) { nhrp_error("nhrp_packet_route called without destination interface"); @@ -1005,7 +1001,7 @@ int nhrp_packet_route(struct nhrp_packet *packet) proto_nexthop = packet->dst_peer->next_hop_address; } else { proto_nexthop = *dst; - do { + for (i = 0; i < 4; i++) { peer = nhrp_peer_route_full( packet->dst_iface, &proto_nexthop, 0, NHRP_PEER_TYPEMASK_ROUTE_VIA_NHS, src, cielist); @@ -1020,7 +1016,12 @@ int nhrp_packet_route(struct nhrp_packet *packet) if (peer->next_hop_address.type == AF_UNSPEC) break; proto_nexthop = peer->next_hop_address; - } while (1); + } + if (i >= 4) { + nhrp_error("Recursive routing for protocol address %s", + nhrp_address_format(dst, sizeof(tmp), tmp)); + return FALSE; + } packet->dst_peer = nhrp_peer_get(peer); } diff --git a/nhrp/nhrp_packet.h b/nhrp/nhrp_packet.h index 3f435c8..c427957 100644 --- a/nhrp/nhrp_packet.h +++ b/nhrp/nhrp_packet.h @@ -1,13 +1,9 @@ /* nhrp_packet.h - In-memory NHRP packet definitions * - * Copyright (C) 2007-2009 Timo Teräs <timo.teras@iki.fi> - * All rights reserved. + * Copyright (c) 2007-2012 Timo Teräs <timo.teras@iki.fi> * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 or later as - * published by the Free Software Foundation. - * - * See http://www.gnu.org/ for details. + * This software is licensed under the MIT License. + * See MIT-LICENSE.txt for additional details. */ #ifndef NHRP_PACKET_H diff --git a/nhrp/nhrp_peer.c b/nhrp/nhrp_peer.c index 7bd1a79..94ba984 100644 --- a/nhrp/nhrp_peer.c +++ b/nhrp/nhrp_peer.c @@ -1,13 +1,9 @@ /* nhrp_peer.c - NHRP peer cache implementation * - * Copyright (C) 2007-2009 Timo Teräs <timo.teras@iki.fi> - * All rights reserved. + * Copyright (c) 2007-2012 Timo Teräs <timo.teras@iki.fi> * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 or later as - * published by the Free Software Foundation. - * - * See http://www.gnu.org/ for details. + * This software is licensed under the MIT License. + * See MIT-LICENSE.txt for additional details. */ #include <stdio.h> @@ -25,9 +21,6 @@ #define NHRP_SCRIPT_TIMEOUT (2*60) #define NHRP_NEGATIVE_CACHE_TIME (3*60) -#define NHRP_EXPIRY_TIME (5*60) - -#define NHRP_HOLDING_TIME_DIVISOR 3 /* See RFC-2332 5.2.3 */ #define NHRP_RETRY_REGISTER_TIME (30 + random()/(RAND_MAX/60)) #define NHRP_RETRY_ERROR_TIME (60 + random()/(RAND_MAX/120)) @@ -50,6 +43,25 @@ const char * const nhrp_peer_type[] = { static int nhrp_peer_num_total = 0; static struct list_head local_peer_list = LIST_INITIALIZER(local_peer_list); +static inline +int holding_time_to_reregister_time(int holding_time) +{ + /* RFC-2332 5.2.3 recommends one third of holding time as + * reregistration interval. */ + return holding_time / 3 + 1; +} + +static inline +int holding_time_to_expiry_time(int holding_time, int offset_time) +{ + /* Reresolution interval */ + int expire; + expire = 2 * holding_time / 3 - offset_time; + if (expire < 0) + expire = 0; + return expire + 1; +} + /* Peer entrys life, pending callbacks and their call order are listed * here. * @@ -495,8 +507,10 @@ static void nhrp_peer_script_route_up_done(union nhrp_peer_event e, int revents) sizeof(tmp), tmp)); peer->flags |= NHRP_PEER_FLAG_UP; - nhrp_peer_schedule(peer, peer->expire_time - NHRP_EXPIRY_TIME - - 10 - ev_now(), nhrp_peer_expire_cb); + nhrp_peer_schedule( + peer, + holding_time_to_expiry_time(peer->expire_time - ev_now(), 10), + nhrp_peer_expire_cb); } else { nhrp_info("[%s] Route up script: %s; " "adding negative cached entry", @@ -681,15 +695,15 @@ static void nhrp_peer_is_up(struct nhrp_peer *peer) case NHRP_PEER_TYPE_CACHED: nhrp_peer_schedule( peer, - peer->expire_time - NHRP_EXPIRY_TIME - ev_now(), + holding_time_to_expiry_time(peer->expire_time - ev_now(), 0), nhrp_peer_expire_cb); break; case NHRP_PEER_TYPE_STATIC: case NHRP_PEER_TYPE_DYNAMIC_NHS: if (peer->flags & NHRP_PEER_FLAG_REGISTER) { nhrp_peer_schedule( - peer, iface->holding_time / - NHRP_HOLDING_TIME_DIVISOR + 1, + peer, + holding_time_to_reregister_time(iface->holding_time), nhrp_peer_send_register_cb); } break; @@ -1595,8 +1609,10 @@ static void nhrp_peer_insert_cb(struct ev_timer *w, int revents) nhrp_peer_run_script(peer, "route-up", nhrp_peer_script_route_up_done); else - nhrp_peer_schedule(peer, peer->expire_time - NHRP_EXPIRY_TIME - - 10 - ev_now(), nhrp_peer_expire_cb); + nhrp_peer_schedule( + peer, + holding_time_to_expiry_time(peer->expire_time - ev_now(), 10), + nhrp_peer_expire_cb); break; case NHRP_PEER_TYPE_NEGATIVE: peer->expire_time = ev_now() + NHRP_NEGATIVE_CACHE_TIME; diff --git a/nhrp/nhrp_peer.h b/nhrp/nhrp_peer.h index 1df5fa9..9f0dd20 100644 --- a/nhrp/nhrp_peer.h +++ b/nhrp/nhrp_peer.h @@ -1,13 +1,9 @@ /* nhrp_peer.h - NHRP peer cache definitions * - * Copyright (C) 2007-2009 Timo Teräs <timo.teras@iki.fi> - * All rights reserved. + * Copyright (c) 2007-2012 Timo Teräs <timo.teras@iki.fi> * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 or later as - * published by the Free Software Foundation. - * - * See http://www.gnu.org/ for details. + * This software is licensed under the MIT License. + * See MIT-LICENSE.txt for additional details. */ #ifndef NHRP_PEER_H diff --git a/nhrp/nhrp_protocol.h b/nhrp/nhrp_protocol.h index 8cf213b..6d34e95 100644 --- a/nhrp/nhrp_protocol.h +++ b/nhrp/nhrp_protocol.h @@ -1,13 +1,9 @@ /* nhrp_protocol.h - NHRP protocol definitions * - * Copyright (C) 2007 Timo Teräs <timo.teras@iki.fi> - * All rights reserved. + * Copyright (c) 2007-2012 Timo Teräs <timo.teras@iki.fi> * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 or later as - * published by the Free Software Foundation. - * - * See http://www.gnu.org/ for details. + * This software is licensed under the MIT License. + * See MIT-LICENSE.txt for additional details. */ #ifndef NHRP_PROTOCOL_H diff --git a/nhrp/nhrp_server.c b/nhrp/nhrp_server.c index b41e4b8..8c35e1c 100644 --- a/nhrp/nhrp_server.c +++ b/nhrp/nhrp_server.c @@ -1,13 +1,9 @@ /* nhrp_server.c - NHRP request handling * - * Copyright (C) 2007-2009 Timo Teräs <timo.teras@iki.fi> - * All rights reserved. + * Copyright (c) 2007-2012 Timo Teräs <timo.teras@iki.fi> * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 or later as - * published by the Free Software Foundation. - * - * See http://www.gnu.org/ for details. + * This software is licensed under the MIT License. + * See MIT-LICENSE.txt for additional details. */ #include <string.h> diff --git a/nhrp/opennhrp.c b/nhrp/opennhrp.c index 8ba870d..4ed27a8 100644 --- a/nhrp/opennhrp.c +++ b/nhrp/opennhrp.c @@ -1,13 +1,9 @@ /* opennhrp.c - OpenNHRP main routines * - * Copyright (C) 2007-2009 Timo Teräs <timo.teras@iki.fi> - * All rights reserved. + * Copyright (c) 2007-2012 Timo Teräs <timo.teras@iki.fi> * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 or later as - * published by the Free Software Foundation. - * - * See http://www.gnu.org/ for details. + * This software is licensed under the MIT License. + * See MIT-LICENSE.txt for additional details. */ #include <ctype.h> diff --git a/nhrp/opennhrpctl.c b/nhrp/opennhrpctl.c index 92fb5b5..60bd161 100644 --- a/nhrp/opennhrpctl.c +++ b/nhrp/opennhrpctl.c @@ -1,13 +1,9 @@ /* opennhrpctl.c - OpenNHRP command line control utility * - * Copyright (C) 2007 Timo Teräs <timo.teras@iki.fi> - * All rights reserved. + * Copyright (c) 2007-2012 Timo Teräs <timo.teras@iki.fi> * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 or later as - * published by the Free Software Foundation. - * - * See http://www.gnu.org/ for details. + * This software is licensed under the MIT License. + * See MIT-LICENSE.txt for additional details. */ #include <errno.h> diff --git a/nhrp/sysdep_netlink.c b/nhrp/sysdep_netlink.c index 0dce865..be529d8 100644 --- a/nhrp/sysdep_netlink.c +++ b/nhrp/sysdep_netlink.c @@ -1,13 +1,9 @@ /* sysdep_netlink.c - Linux netlink glue * - * Copyright (C) 2007-2009 Timo Teräs <timo.teras@iki.fi> - * All rights reserved. + * Copyright (c) 2007-2012 Timo Teräs <timo.teras@iki.fi> * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 or later as - * published by the Free Software Foundation. - * - * See http://www.gnu.org/ for details. + * This software is licensed under the MIT License. + * See MIT-LICENSE.txt for additional details. */ #include <time.h> diff --git a/nhrp/sysdep_pfpacket.c b/nhrp/sysdep_pfpacket.c index 514b848..527b866 100644 --- a/nhrp/sysdep_pfpacket.c +++ b/nhrp/sysdep_pfpacket.c @@ -1,13 +1,9 @@ /* sysdep_pfpacket.c - Tracing of forwarded packets using PF_PACKET * - * Copyright (C) 2007-2009 Timo Teräs <timo.teras@iki.fi> - * All rights reserved. + * Copyright (c) 2007-2012 Timo Teräs <timo.teras@iki.fi> * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 or later as - * published by the Free Software Foundation. - * - * See http://www.gnu.org/ for details. + * This software is licensed under the MIT License. + * See MIT-LICENSE.txt for additional details. */ #include <errno.h> @@ -30,8 +26,6 @@ #include "nhrp_interface.h" #include "nhrp_peer.h" -#define MAX_OPCODES 100 - struct multicast_packet { struct nhrp_interface *iface; struct sockaddr_ll lladdr; @@ -61,13 +55,35 @@ enum { struct filter { int pos[NUM_LABELS]; - int numops; - struct sock_filter code[MAX_OPCODES]; + int numops, numalloc; + struct sock_filter *code; }; +static int checkfilter(struct filter *f) +{ + if (f->numops < f->numalloc) + return 1; + + if (f->numalloc < 0) + return 0; + + if (f->numalloc) + f->numalloc *= 2; + else + f->numalloc = 128; + + f->code = realloc(f->code, f->numalloc * sizeof(struct sock_filter)); + if (f->code == NULL) { + f->numalloc = -1; + return 0; + } + + return 1; +} + static void emit_stmt(struct filter *f, __u16 code, __u32 k) { - if (f->numops < MAX_OPCODES) { + if (checkfilter(f)) { f->code[f->numops].code = code; f->code[f->numops].jt = 0; f->code[f->numops].jf = 0; @@ -78,7 +94,7 @@ static void emit_stmt(struct filter *f, __u16 code, __u32 k) static void emit_jump(struct filter *f, __u16 code, __u32 k, __u8 jt, __u8 jf) { - if (f->numops < MAX_OPCODES) { + if (checkfilter(f)) { f->code[f->numops].code = code; f->code[f->numops].jt = jt; f->code[f->numops].jf = jf; @@ -196,8 +212,8 @@ static void install_filter_cb(struct ev_timer *w, int revents) emit_stmt(&f, BPF_RET|BPF_K, 0); /* All ok so far? */ - if (f.numops >= MAX_OPCODES) { - nhrp_error("Filter code buffer too small (code actual length %d)", + if (f.numalloc < 0) { + nhrp_error("Unable to construct filter code: out of memory (code actual length %d)", f.numops); return; } @@ -217,9 +233,11 @@ static void install_filter_cb(struct ev_timer *w, int revents) prog.filter = f.code; if (setsockopt(packet_io.fd, SOL_SOCKET, SO_ATTACH_FILTER, &prog, sizeof(prog))) - return; + nhrp_perror("Failed to install filter code"); + else + nhrp_info("Filter code installed (%d opcodes)", f.numops); - nhrp_info("Filter code installed (%d opcodes)", f.numops); + free(f.code); } int forward_local_addresses_changed(void) diff --git a/nhrp/sysdep_syslog.c b/nhrp/sysdep_syslog.c index c8f9f7e..3004be8 100644 --- a/nhrp/sysdep_syslog.c +++ b/nhrp/sysdep_syslog.c @@ -1,13 +1,9 @@ /* sysdep_syslog.c - Logging via syslog * - * Copyright (C) 2007 Timo Teräs <timo.teras@iki.fi> - * All rights reserved. + * Copyright (c) 2007-2012 Timo Teräs <timo.teras@iki.fi> * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 or later as - * published by the Free Software Foundation. - * - * See http://www.gnu.org/ for details. + * This software is licensed under the MIT License. + * See MIT-LICENSE.txt for additional details. */ #include <errno.h> |