lib/mdns/src/NetworkInterfaces.h
changeset 2289 10ad22c88dbb
child 2310a2bf097f3756
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/lib/mdns/src/NetworkInterfaces.h	Thu Mar 26 01:25:34 2009 +0100
     1.3 @@ -0,0 +1,145 @@
     1.4 +/*
     1.5 +OLSR MDNS plugin.
     1.6 +Written by Saverio Proto <zioproto@gmail.com> and Claudio Pisa <clauz@ninux.org>.
     1.7 +
     1.8 +    This file is part of OLSR MDNS PLUGIN.
     1.9 +
    1.10 +    The OLSR MDNS PLUGIN is free software: you can redistribute it and/or modify
    1.11 +    it under the terms of the GNU General Public License as published by
    1.12 +    the Free Software Foundation, either version 3 of the License, or
    1.13 +    (at your option) any later version.
    1.14 +
    1.15 +    The OLSR MDNS PLUGIN is distributed in the hope that it will be useful,
    1.16 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.17 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1.18 +    GNU General Public License for more details.
    1.19 +
    1.20 +    You should have received a copy of the GNU General Public License
    1.21 +    along with Foobar.  If not, see <http://www.gnu.org/licenses/>.
    1.22 +
    1.23 +
    1.24 + */
    1.25 +
    1.26 +
    1.27 +#ifndef _BMF_NETWORKINTERFACES_H
    1.28 +#define _BMF_NETWORKINTERFACES_H
    1.29 +
    1.30 +/* System includes */
    1.31 +#include <netinet/in.h> /* struct in_addr */
    1.32 +
    1.33 +/* OLSR includes */
    1.34 +#include "olsr_types.h" /* olsr_ip_addr */
    1.35 +#include "plugin.h" /* union set_plugin_parameter_addon */
    1.36 +
    1.37 +/* Plugin includes */
    1.38 +#include "Packet.h" /* IFHWADDRLEN */
    1.39 +#include "mdns.h"
    1.40 +/* Size of buffer in which packets are received */
    1.41 +#define BMF_BUFFER_SIZE 2048
    1.42 +
    1.43 +struct TBmfInterface
    1.44 +{
    1.45 +  /* File descriptor of raw packet socket, used for capturing multicast packets */
    1.46 +  int capturingSkfd;
    1.47 +
    1.48 +  /* File descriptor of UDP (datagram) socket for encapsulated multicast packets.
    1.49 +   * Only used for OLSR-enabled interfaces; set to -1 if interface is not OLSR-enabled. */
    1.50 +  int encapsulatingSkfd;
    1.51 +
    1.52 +  /* File descriptor of UDP packet socket, used for listening to encapsulation packets.
    1.53 +   * Used only when PlParam "BmfMechanism" is set to "UnicastPromiscuous". */
    1.54 +  int listeningSkfd;
    1.55 +
    1.56 +  unsigned char macAddr[IFHWADDRLEN];
    1.57 +
    1.58 +  char ifName[IFNAMSIZ];
    1.59 +
    1.60 +  /* OLSRs idea of this network interface. NULL if this interface is not
    1.61 +   * OLSR-enabled. */
    1.62 +  struct interface* olsrIntf;
    1.63 +
    1.64 +  /* IP address of this network interface */
    1.65 +  union olsr_ip_addr intAddr;
    1.66 +
    1.67 +  /* Broadcast address of this network interface */
    1.68 +  union olsr_ip_addr broadAddr;
    1.69 +
    1.70 +  #define FRAGMENT_HISTORY_SIZE 10
    1.71 +  struct TFragmentHistory
    1.72 +  {
    1.73 +    u_int16_t ipId;
    1.74 +    u_int8_t ipProto;
    1.75 +    struct in_addr ipSrc;
    1.76 +    struct in_addr ipDst;
    1.77 +  } fragmentHistory [FRAGMENT_HISTORY_SIZE];
    1.78 +
    1.79 +  int nextFragmentHistoryEntry;
    1.80 +
    1.81 +  /* Number of received and transmitted BMF packets on this interface */
    1.82 +  u_int32_t nBmfPacketsRx;
    1.83 +  u_int32_t nBmfPacketsRxDup;
    1.84 +  u_int32_t nBmfPacketsTx;
    1.85 +
    1.86 +  /* Next element in list */
    1.87 +  struct TBmfInterface* next;
    1.88 +};
    1.89 +
    1.90 +extern struct TBmfInterface* BmfInterfaces;
    1.91 +
    1.92 +extern int HighestSkfd;
    1.93 +extern fd_set InputSet;
    1.94 +
    1.95 +extern int EtherTunTapFd;
    1.96 +
    1.97 +extern char EtherTunTapIfName[];
    1.98 +
    1.99 +/* 10.255.255.253 in host byte order */
   1.100 +#define ETHERTUNTAPDEFAULTIP 0x0AFFFFFD
   1.101 +
   1.102 +extern u_int32_t EtherTunTapIp;
   1.103 +extern u_int32_t EtherTunTapIpMask;
   1.104 +extern u_int32_t EtherTunTapIpBroadcast;
   1.105 +
   1.106 +
   1.107 +enum TBmfMechanism { BM_BROADCAST = 0, BM_UNICAST_PROMISCUOUS };
   1.108 +extern enum TBmfMechanism BmfMechanism;
   1.109 +
   1.110 +int SetBmfInterfaceName(const char* ifname, void* data, set_plugin_parameter_addon addon);
   1.111 +int SetBmfInterfaceIp(const char* ip, void* data, set_plugin_parameter_addon addon);
   1.112 +int SetCapturePacketsOnOlsrInterfaces(const char* enable, void* data, set_plugin_parameter_addon addon);
   1.113 +int SetBmfMechanism(const char* mechanism, void* data, set_plugin_parameter_addon addon);
   1.114 +int DeactivateSpoofFilter(void);
   1.115 +void RestoreSpoofFilter(void);
   1.116 +
   1.117 +#define MAX_UNICAST_NEIGHBORS 10
   1.118 +struct TBestNeighbors
   1.119 +{
   1.120 +  struct link_entry* links[MAX_UNICAST_NEIGHBORS];
   1.121 +};
   1.122 +
   1.123 +void FindNeighbors(
   1.124 +  struct TBestNeighbors* neighbors,
   1.125 +  struct link_entry** bestNeighbor,
   1.126 +  struct TBmfInterface* intf,
   1.127 +  union olsr_ip_addr* source,
   1.128 +  union olsr_ip_addr* forwardedBy,
   1.129 +  union olsr_ip_addr* forwardedTo,
   1.130 +  int* nPossibleNeighbors);
   1.131 +
   1.132 +int CreateBmfNetworkInterfaces(struct interface* skipThisIntf);
   1.133 +void AddInterface(struct interface* newIntf);
   1.134 +void CloseBmfNetworkInterfaces(void);
   1.135 +int AddNonOlsrBmfIf(const char* ifName, void* data, set_plugin_parameter_addon addon);
   1.136 +int IsNonOlsrBmfIf(const char* ifName);
   1.137 +void CheckAndUpdateLocalBroadcast(unsigned char* ipPacket, union olsr_ip_addr* broadAddr);
   1.138 +void AddMulticastRoute(void);
   1.139 +void DeleteMulticastRoute(void);
   1.140 +
   1.141 +#endif /* _BMF_NETWORKINTERFACES_H */
   1.142 +
   1.143 +/*
   1.144 + * Local Variables:
   1.145 + * c-basic-offset: 2
   1.146 + * indent-tabs-mode: nil
   1.147 + * End:
   1.148 + */