From: Ferry Huberts Date: Wed, 29 Jan 2014 09:39:49 +0000 (+0100) Subject: p2pd: add UseTTLDecrement configuration setting X-Git-Tag: v0.6.7~41^2~41 X-Git-Url: http://olsr.org/git/?p=olsrd.git;a=commitdiff_plain;h=7996735cec7058153aa675bc402c08e058862079 p2pd: add UseTTLDecrement configuration setting Signed-off-by: Ferry Huberts --- diff --git a/lib/p2pd/README b/lib/p2pd/README index c89f2922..b5c44a50 100644 --- a/lib/p2pd/README +++ b/lib/p2pd/README @@ -67,6 +67,8 @@ PlParam "P2pdTtl" "5" PlParam "UdpDestPort" "255.255.255.255 1211" # MDNS multicast (draft-cheshire-dnsext-multicastdns) PlParam "UdpDestPort" "224.0.0.251 5353" +# Set to 1 to decrement the TTL on the packet going into the OLSR network (default 0) +#PlParam "UseTTLDecrement" "0" } Where eth0 and eth1 are the names of the interfaces where you want to capture diff --git a/lib/p2pd/src/olsrd_plugin.c b/lib/p2pd/src/olsrd_plugin.c index 737cef87..da2d9c0c 100644 --- a/lib/p2pd/src/olsrd_plugin.c +++ b/lib/p2pd/src/olsrd_plugin.c @@ -112,6 +112,7 @@ static const struct olsrd_plugin_parameters plugin_parameters[] = { {.name = "P2pdTtl", .set_plugin_parameter = &SetP2pdTtl, .data = NULL }, {.name = "UdpDestPort",.set_plugin_parameter = &AddUdpDestPort,.data = NULL}, {.name = "UseHashFilter",.set_plugin_parameter = &SetP2pdUseHashFilter,.data = NULL}, + {.name = "UseTTLDecrement",.set_plugin_parameter = &SetP2pdUseTtlDecrement,.data = NULL}, }; /* ------------------------------------------------------------------------- diff --git a/lib/p2pd/src/p2pd.c b/lib/p2pd/src/p2pd.c index b696c4fc..f9db2a7e 100644 --- a/lib/p2pd/src/p2pd.c +++ b/lib/p2pd/src/p2pd.c @@ -85,6 +85,7 @@ int P2pdTtl = 0; int P2pdUseHash = 0; /* Switch off hash filter by default */ +int P2pdUseTtlDecrement = 0; /* No TTL decrement by default */ int P2pdDuplicateTimeout = P2PD_VALID_TIME; /* List of UDP destination address and port information */ @@ -622,6 +623,7 @@ P2pdPacketCaptured(unsigned char *encapsulationUdpData, int nBytes) struct ip *ipHeader; /* The IP header inside the captured IP packet */ struct ip6_hdr *ipHeader6; /* The IP header inside the captured IP packet */ struct udphdr *udpHeader; + uint8_t * ttl = NULL; u_int16_t destPort; if ((encapsulationUdpData[0] & 0xf0) == 0x40) { //IPV4 @@ -662,6 +664,8 @@ P2pdPacketCaptured(unsigned char *encapsulationUdpData, int nBytes) #endif /* INCLUDE_DEBUG_OUTPUT */ return; } + + ttl = &ipHeader->ip_ttl; } //END IPV4 else if ((encapsulationUdpData[0] & 0xf0) == 0x60) { //IPv6 @@ -703,11 +707,24 @@ P2pdPacketCaptured(unsigned char *encapsulationUdpData, int nBytes) #endif /* INCLUDE_DEBUG_OUTPUT */ return; } + + ttl = &ipHeader6->ip6_ctlun.ip6_un1.ip6_un1_hlim; } //END IPV6 else { return; //Is not IP packet } + if (P2pdUseTtlDecrement) { + assert(ttl); + if (!*ttl) { + return; + } + *ttl -= 1; + if (!*ttl) { + return; + } + } + // send the packet to OLSR forward mechanism olsr_p2pd_gen(encapsulationUdpData, nBytes); } /* P2pdPacketCaptured */ @@ -861,6 +878,27 @@ SetP2pdUseHashFilter(const char *value, return 0; } +/* ------------------------------------------------------------------------- + * Function : SetP2pdUseTtlDecrement + * Description: Set the TTL decrement lag for this plug-in + * Input : value - parameter value to evaluate + * data - data associated with this parameter (unused in this app) + * addon - additional parameter data + * Output : none + * Return : Always 0 + * Data Used : P2pdUseTtlDecrement + * ------------------------------------------------------------------------- */ +int +SetP2pdUseTtlDecrement(const char *value, + void *data __attribute__ ((unused)), + set_plugin_parameter_addon addon __attribute__ ((unused))) +{ + assert(value != NULL); + P2pdUseTtlDecrement = atoi(value); + + return 0; +} + /* ------------------------------------------------------------------------- * Function : AddUdpDestPort * Description: Set the UDP destination/port combination as an entry in the diff --git a/lib/p2pd/src/p2pd.h b/lib/p2pd/src/p2pd.h index 4f90bbf9..5d1762f1 100644 --- a/lib/p2pd/src/p2pd.h +++ b/lib/p2pd/src/p2pd.h @@ -99,6 +99,7 @@ int AddUdpDestPort(const char *value, void *data __attribute__ ((unused)), set_p bool InUdpDestPortList(int ip_version, union olsr_ip_addr *addr, uint16_t port); int SetP2pdTtl(const char *value, void *data __attribute__ ((unused)), set_plugin_parameter_addon addon __attribute__ ((unused))); int SetP2pdUseHashFilter(const char *value, void *data __attribute__ ((unused)), set_plugin_parameter_addon addon __attribute__ ((unused))); +int SetP2pdUseTtlDecrement(const char *value, void *data __attribute__ ((unused)), set_plugin_parameter_addon addon __attribute__ ((unused))); bool p2pd_message_seen(struct node **head, struct node **tail, union olsr_message *m); void p2pd_store_message(struct node **head, struct node **tail, union olsr_message *m); bool p2pd_is_duplicate_message(union olsr_message *msg);