diff --git a/lib/dnssd/src/NetworkInterfaces.c b/lib/dnssd/src/NetworkInterfaces.c index e37b1c19..a93a6739 100644 --- a/lib/dnssd/src/NetworkInterfaces.c +++ b/lib/dnssd/src/NetworkInterfaces.c @@ -449,27 +449,6 @@ CreateNonOlsrNetworkInterfaces(struct interface *skipThisIntf) return 0; } /* CreateNonOlsrNetworkInterfaces */ -/* ------------------------------------------------------------------------- - * Function : AddInterface - * Description: Add an OLSR-enabled network interface to the list of BMF-enabled - * network interfaces - * Input : newIntf - network interface to add - * Output : none - * Return : none - * Data Used : none - * ------------------------------------------------------------------------- */ -void -AddInterface(struct interface *newIntf) -{ - /* int nOpened; */ - - assert(newIntf != NULL); - - /* nOpened = */ (void)CreateInterface(newIntf->int_name, NULL, newIntf); - - //OLSR_PRINTF(1, "%s: opened %d sockets\n", PLUGIN_NAME, nOpened); -} /* AddInterface */ - /* ------------------------------------------------------------------------- * Function : CloseNonOlsrNetworkInterfaces * Description: Closes every socket on each network interface used by BMF diff --git a/lib/dnssd/src/NetworkInterfaces.h b/lib/dnssd/src/NetworkInterfaces.h index 05319469..18ab9cbc 100644 --- a/lib/dnssd/src/NetworkInterfaces.h +++ b/lib/dnssd/src/NetworkInterfaces.h @@ -122,32 +122,15 @@ extern u_int32_t EtherTunTapIpBroadcast; enum P2pdMechanism { BM_BROADCAST = 0, BM_UNICAST_PROMISCUOUS }; extern enum P2pdMechanism P2pdMechanism; -int SetNonOlsrInterfaceName(const char *ifname, void *data, set_plugin_parameter_addon addon); -int SetNonOlsrInterfaceIp(const char *ip, void *data, set_plugin_parameter_addon addon); -int SetCapturePacketsOnOlsrInterfaces(const char *enable, void *data, set_plugin_parameter_addon addon); -int SetP2pdMechanism(const char *mechanism, void *data, set_plugin_parameter_addon addon); -int DeactivateSpoofFilter(void); -void RestoreSpoofFilter(void); - #define MAX_UNICAST_NEIGHBORS 10 struct TBestNeighbors { struct link_entry *links[MAX_UNICAST_NEIGHBORS]; }; -void FindNeighbors(struct TBestNeighbors *neighbors, - struct link_entry **bestNeighbor, - struct DnssdInterface *intf, - union olsr_ip_addr *source, - union olsr_ip_addr *forwardedBy, union olsr_ip_addr *forwardedTo, int *nPossibleNeighbors); - int CreateNonOlsrNetworkInterfaces(struct interface *skipThisIntf); -void AddInterface(struct interface *newIntf); void CloseNonOlsrNetworkInterfaces(void); int AddNonOlsrIf(const char *ifName, void *data, set_plugin_parameter_addon addon); int IsNonOlsrIf(const char *ifName); -void CheckAndUpdateLocalBroadcast(unsigned char *ipPacket, union olsr_ip_addr *broadAddr); -void AddMulticastRoute(void); -void DeleteMulticastRoute(void); int CreateEncapsulationSocket(const char *ifName); int CreateCaptureSocket(const char *ifName); diff --git a/lib/dnssd/src/Packet.c b/lib/dnssd/src/Packet.c index c7f6daad..9bb38e66 100644 --- a/lib/dnssd/src/Packet.c +++ b/lib/dnssd/src/Packet.c @@ -49,28 +49,6 @@ #include /* ntohs(), htons() */ #include /* struct iphdr */ -/* ------------------------------------------------------------------------- - * Function : IsIpFragment - * Description: Check if an IP packet is an IP fragment - * Input : ipPacket - the IP packet - * Output : none - * Return : true (1) or false (0) - * Data Used : none - * ------------------------------------------------------------------------- */ -int IsIpFragment(unsigned char* ipPacket) -{ - struct ip* iph; - - assert(ipPacket != NULL); - - iph = (struct ip*) ARM_NOWARN_ALIGN(ipPacket); - if ((ntohs(iph->ip_off) & IP_OFFMASK) != 0) - { - return 1; - } - return 0; -} /* IsIpFragment */ - /* ------------------------------------------------------------------------- * Function : GetIpTotalLength * Description: Retrieve the total length of the IP packet (in bytes) of @@ -109,16 +87,6 @@ int IsIpv4Fragment(struct ip* hdr) return 0; } /* IsIpv4Fragment */ -int IsMulticastv4(struct ip* hdr) -{ - assert(hdr != NULL); - - if (IN_MULTICAST(ntohl(hdr->ip_dst.s_addr))) - return 1; - - return 0; -} - /* ------------------------------------------------------------------------- * Function : IsIpv6Fragment @@ -139,14 +107,6 @@ int IsIpv6Fragment(struct ip6_hdr* hdr __attribute__ ((unused))) return 0; } -int IsMulticastv6(struct ip6_hdr* hdr __attribute__ ((unused))) -{ - assert(hdr != NULL); - - - return 0; -} - /* ------------------------------------------------------------------------- * Function : GetIpHeaderLength * Description: Retrieve the IP header length (in bytes) of an IP packet @@ -180,25 +140,6 @@ GetIpPacket(unsigned char *encapsulationUdpData) return encapsulationUdpData + ENCAP_HDR_LEN; } /* GetIpPacket */ -/* ------------------------------------------------------------------------- - * Function : GetTtl - * Description: Retrieve the TTL (Time To Live) value from the IP header of - * an IP packet - * Input : ipPacket - the IP packet - * Output : none - * Return : TTL value - * Data Used : none - * ------------------------------------------------------------------------- */ -u_int8_t GetTtl(unsigned char* ipPacket) -{ - struct iphdr* iph; - - assert(ipPacket != NULL); - - iph = (struct iphdr*) ARM_NOWARN_ALIGN(ipPacket); - return iph->ttl; -} /* GetTtl */ - /* ------------------------------------------------------------------------- * Function : SaveTtlAndChecksum * Description: Save the TTL (Time To Live) value and IP checksum as found in @@ -240,33 +181,6 @@ void RestoreTtlAndChecksum(unsigned char* ipPacket, struct TSaveTtl* sttl) iph->check = htons(sttl->check); } /* RestoreTtlAndChecksum */ -/* ------------------------------------------------------------------------- - * Function : DecreaseTtlAndUpdateHeaderChecksum - * Description: For an IP packet, decrement the TTL value and update the IP header - * checksum accordingly. - * Input : ipPacket - the IP packet - * Output : none - * Return : none - * Data Used : none - * Notes : See also RFC1141 - * ------------------------------------------------------------------------- */ -void DecreaseTtlAndUpdateHeaderChecksum(unsigned char* ipPacket) -{ - struct iphdr* iph; - u_int32_t sum; - - assert(ipPacket != NULL); - - iph = (struct iphdr*) ARM_NOWARN_ALIGN(ipPacket); - - iph->ttl--; /* decrement ttl */ - sum = ntohs(iph->check) + 0x100; /* increment checksum high byte */ - iph->check = htons(sum + (sum>>16)); /* add carry */ -} /* DecreaseTtlAndUpdateHeaderChecksum */ - - - - /* * Local Variables: * c-basic-offset: 2 diff --git a/lib/dnssd/src/Packet.h b/lib/dnssd/src/Packet.h index 0804d0ad..95ec516a 100644 --- a/lib/dnssd/src/Packet.h +++ b/lib/dnssd/src/Packet.h @@ -68,16 +68,11 @@ struct TEncapHeader { #define ENCAP_HDR_LEN ((int)sizeof(struct TEncapHeader)) -int IsIpFragment(unsigned char* ipPacket); u_int16_t GetIpTotalLength(unsigned char* ipPacket); int IsIpv4Fragment(struct ip*); -int IsMulticastv4(struct ip*); int IsIpv6Fragment(struct ip6_hdr*); -int IsMulticastv6(struct ip6_hdr*); -u_int8_t GetTtl(unsigned char* ipPacket); void SaveTtlAndChecksum(unsigned char* ipPacket, struct TSaveTtl* sttl); void RestoreTtlAndChecksum(unsigned char* ipPacket, struct TSaveTtl* sttl); -void DecreaseTtlAndUpdateHeaderChecksum(unsigned char* ipPacket); unsigned int GetIpHeaderLength(unsigned char *ipPacket); unsigned char *GetIpPacket(unsigned char *encapsulationUdpData); diff --git a/lib/dnssd/src/PacketHistory.h b/lib/dnssd/src/PacketHistory.h index 3fb8151f..2cf41cd2 100644 --- a/lib/dnssd/src/PacketHistory.h +++ b/lib/dnssd/src/PacketHistory.h @@ -61,7 +61,6 @@ struct TDupEntry void InitPacketHistory(void); u_int32_t PacketCrc32(unsigned char* ipPkt, ssize_t len); u_int32_t Hash(u_int32_t from32); -void MarkRecentPacket(u_int32_t crc32); int CheckAndMarkRecentPacket(u_int32_t crc32); void PrunePacketHistory(void*); diff --git a/lib/dnssd/src/dnssd.c b/lib/dnssd/src/dnssd.c index c9fc7122..95585353 100644 --- a/lib/dnssd/src/dnssd.c +++ b/lib/dnssd/src/dnssd.c @@ -488,11 +488,12 @@ olsr_p2pd_gen(unsigned char *packet, int len, int ttl) //OLSR_PRINTF(1, "%s: Generating packet - [%s]\n", PLUGIN_NAME_SHORT, ifn->int_name); if (net_outbuffer_push(ifn, message, aligned_size) != aligned_size) { - /* send data and try again */ + /* flush output buffer and try again */ net_output(ifn); if (net_outbuffer_push(ifn, message, aligned_size) != aligned_size) { - //OLSR_PRINTF(1, "%s: could not send on interface: %s\n", PLUGIN_NAME_SHORT, ifn->int_name); - } + OLSR_PRINTF(1, "%s: could not send on interface: %s\n", PLUGIN_NAME_SHORT, ifn->int_name); + } else + net_output(ifn); } else net_output(ifn); } @@ -533,27 +534,6 @@ P2pdPError(const char *format, ...) } } /* P2pdPError */ -/* ------------------------------------------------------------------------- - * Function : MainAddressOf - * Description: Lookup the main address of a node - * Input : ip - IP address of the node - * Output : none - * Return : The main IP address of the node - * Data Used : none - * ------------------------------------------------------------------------- */ -union olsr_ip_addr * -MainAddressOf(union olsr_ip_addr *ip) -{ - union olsr_ip_addr *result = NULL; - - /* TODO: mid_lookup_main_addr() is not thread-safe! */ - result = mid_lookup_main_addr(ip); - if (result == NULL) { - result = ip; - } - return result; -} /* MainAddressOf */ - /* ------------------------------------------------------------------------- * Function : InUdpDestPortList diff --git a/lib/dnssd/src/dnssd.h b/lib/dnssd/src/dnssd.h index 610764d4..aeecfd71 100644 --- a/lib/dnssd/src/dnssd.h +++ b/lib/dnssd/src/dnssd.h @@ -140,7 +140,6 @@ extern struct DuplicateFilterEntry * FilterList; void DoP2pd(int sd, void *x, unsigned int y); void P2pdPError(const char *format, ...) __attribute__ ((format(printf, 1, 2))); -union olsr_ip_addr *MainAddressOf(union olsr_ip_addr *ip); int InitP2pd(struct interface *skipThisIntf); void CloseP2pd(void); int AddUdpDestPort(const char *value, void *data __attribute__ ((unused)), set_plugin_parameter_addon addon __attribute__ ((unused))); @@ -157,7 +156,6 @@ void olsr_p2pd_gen(unsigned char *packet, int len, int ttl); bool olsr_parser(union olsr_message *, struct interface *, union olsr_ip_addr *); int SetupServiceList(const char *value, void *data __attribute__ ((unused)), set_plugin_parameter_addon addon __attribute__ ((unused))); -void PromptAnnouncements(void *context __attribute__((unused))); int SetDomain(const char *value, void *data __attribute__ ((unused)), set_plugin_parameter_addon addon __attribute__ ((unused))); void UpdateServices(void *context); diff --git a/lib/mdp/src/olsrd_mdp.c b/lib/mdp/src/olsrd_mdp.c index aac3bda8..5f572192 100644 --- a/lib/mdp/src/olsrd_mdp.c +++ b/lib/mdp/src/olsrd_mdp.c @@ -98,7 +98,6 @@ #define CO_APPEND_BIN(R,S,L) CHECK(co_request_append_bin(co_req,(char*)S,L),"Failed to append to request") static struct timeval now; -co_obj_t *co_req = NULL, *co_resp = NULL; /* Timestamp node */ struct stamp { @@ -165,28 +164,34 @@ mdp_checksum(uint8_t *data, const uint16_t data_len, { unsigned char *sig = NULL; size_t sig_len = 0; - co_obj_t *co_conn = NULL; + co_obj_t *co_conn = NULL, *co_req = NULL, *co_resp = NULL; CHECKF((co_conn = co_connect(config_commotionsock,strlen(config_commotionsock)+1)),"Failed to connect to Commotion socket\n\n"); - CHECK_MEM((co_req = co_request_create())); + co_req = co_request_create(); + CHECK_MEM(co_req); CO_APPEND_BIN(co_req,servald_key,servald_key_len); CO_APPEND_BIN(co_req,data,data_len); - CHECK(co_call(co_conn,&co_resp,"mdp-sign",sizeof("mdp-sign"),co_req) && - (sig_len = co_response_get_bin(co_resp,(char**)&sig,"sig",sizeof("sig"))),"Failed to receive signature from commotiond"); + int call_ret = co_call(co_conn,&co_resp,"mdp-sign",sizeof("mdp-sign"),co_req); + CHECK(call_ret, "Failed to receive signature from commotiond"); + sig_len = co_response_get_bin(co_resp,(char**)&sig,"sig",sizeof("sig")); + CHECK(sig_len, "Received invalid signature from commotiond"); if (sig_len <= sigbuf_len) { CHECK_MEM(memcpy(sigbuf,sig,sig_len)); } else { olsr_printf(1, "Signature too big for signature buffer!\n"); } - - co_free(co_req); - co_free(co_resp); print_data("signature", sigbuf, sig_len); -error: +error: + if (co_req) + co_free(co_req); + + if (co_resp) + co_free(co_resp); + /* * We can't be sure that we need to disconnect. But * we need to if there is a connection. @@ -211,6 +216,7 @@ mdp_plugin_init(void) { int i; co_obj_t *co_conn = NULL; + struct interface *ifn = NULL; /* Initialize the timestamp database */ for (i = 0; i < HASHSIZE; i++) { @@ -232,6 +238,11 @@ mdp_plugin_init(void) CHECKF(read_key_from_servald(co_conn, config_keyringpath, config_sid) == 0,"[MDP] Could not read key from servald sid!\nExiting!\n\n"); + /* loop through interfaces, reserving buffer space for signatures */ + for (ifn = ifnet; ifn; ifn = ifn->int_next) { + CHECKF(net_reserve_bufspace(ifn, sizeof(struct s_olsrmsg)) == 0, "Error reserving buffer space for signatures"); + } + /* Register the packet transform function */ add_ptf(&add_signature); @@ -1125,6 +1136,7 @@ static int read_key_from_servald(co_obj_t *co_conn, const char *keyring_path, const char *sid) { char *output = NULL; + co_obj_t *co_req = NULL, *co_resp = NULL; assert(co_conn); CHECKF_MEM((co_req = co_request_create()));