lib/mdns/src/NetworkInterfaces.h
author Saverio Proto <zioproto@gmail.com>
Thu Mar 26 01:25:34 2009 +0100 (3 years ago)
changeset 2289 10ad22c88dbb
child 2310a2bf097f3756
permissions -rw-r--r--
Adding first version of the OLSR mdns plugin written by Saverio Proto and
Claudio Pisa (Ninux.org)
     1 /*
     2 OLSR MDNS plugin.
     3 Written by Saverio Proto <zioproto@gmail.com> and Claudio Pisa <clauz@ninux.org>.
     4 
     5     This file is part of OLSR MDNS PLUGIN.
     6 
     7     The OLSR MDNS PLUGIN is free software: you can redistribute it and/or modify
     8     it under the terms of the GNU General Public License as published by
     9     the Free Software Foundation, either version 3 of the License, or
    10     (at your option) any later version.
    11 
    12     The OLSR MDNS PLUGIN is distributed in the hope that it will be useful,
    13     but WITHOUT ANY WARRANTY; without even the implied warranty of
    14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    15     GNU General Public License for more details.
    16 
    17     You should have received a copy of the GNU General Public License
    18     along with Foobar.  If not, see <http://www.gnu.org/licenses/>.
    19 
    20 
    21  */
    22 
    23 
    24 #ifndef _BMF_NETWORKINTERFACES_H
    25 #define _BMF_NETWORKINTERFACES_H
    26 
    27 /* System includes */
    28 #include <netinet/in.h> /* struct in_addr */
    29 
    30 /* OLSR includes */
    31 #include "olsr_types.h" /* olsr_ip_addr */
    32 #include "plugin.h" /* union set_plugin_parameter_addon */
    33 
    34 /* Plugin includes */
    35 #include "Packet.h" /* IFHWADDRLEN */
    36 #include "mdns.h"
    37 /* Size of buffer in which packets are received */
    38 #define BMF_BUFFER_SIZE 2048
    39 
    40 struct TBmfInterface
    41 {
    42   /* File descriptor of raw packet socket, used for capturing multicast packets */
    43   int capturingSkfd;
    44 
    45   /* File descriptor of UDP (datagram) socket for encapsulated multicast packets.
    46    * Only used for OLSR-enabled interfaces; set to -1 if interface is not OLSR-enabled. */
    47   int encapsulatingSkfd;
    48 
    49   /* File descriptor of UDP packet socket, used for listening to encapsulation packets.
    50    * Used only when PlParam "BmfMechanism" is set to "UnicastPromiscuous". */
    51   int listeningSkfd;
    52 
    53   unsigned char macAddr[IFHWADDRLEN];
    54 
    55   char ifName[IFNAMSIZ];
    56 
    57   /* OLSRs idea of this network interface. NULL if this interface is not
    58    * OLSR-enabled. */
    59   struct interface* olsrIntf;
    60 
    61   /* IP address of this network interface */
    62   union olsr_ip_addr intAddr;
    63 
    64   /* Broadcast address of this network interface */
    65   union olsr_ip_addr broadAddr;
    66 
    67   #define FRAGMENT_HISTORY_SIZE 10
    68   struct TFragmentHistory
    69   {
    70     u_int16_t ipId;
    71     u_int8_t ipProto;
    72     struct in_addr ipSrc;
    73     struct in_addr ipDst;
    74   } fragmentHistory [FRAGMENT_HISTORY_SIZE];
    75 
    76   int nextFragmentHistoryEntry;
    77 
    78   /* Number of received and transmitted BMF packets on this interface */
    79   u_int32_t nBmfPacketsRx;
    80   u_int32_t nBmfPacketsRxDup;
    81   u_int32_t nBmfPacketsTx;
    82 
    83   /* Next element in list */
    84   struct TBmfInterface* next;
    85 };
    86 
    87 extern struct TBmfInterface* BmfInterfaces;
    88 
    89 extern int HighestSkfd;
    90 extern fd_set InputSet;
    91 
    92 extern int EtherTunTapFd;
    93 
    94 extern char EtherTunTapIfName[];
    95 
    96 /* 10.255.255.253 in host byte order */
    97 #define ETHERTUNTAPDEFAULTIP 0x0AFFFFFD
    98 
    99 extern u_int32_t EtherTunTapIp;
   100 extern u_int32_t EtherTunTapIpMask;
   101 extern u_int32_t EtherTunTapIpBroadcast;
   102 
   103 
   104 enum TBmfMechanism { BM_BROADCAST = 0, BM_UNICAST_PROMISCUOUS };
   105 extern enum TBmfMechanism BmfMechanism;
   106 
   107 int SetBmfInterfaceName(const char* ifname, void* data, set_plugin_parameter_addon addon);
   108 int SetBmfInterfaceIp(const char* ip, void* data, set_plugin_parameter_addon addon);
   109 int SetCapturePacketsOnOlsrInterfaces(const char* enable, void* data, set_plugin_parameter_addon addon);
   110 int SetBmfMechanism(const char* mechanism, void* data, set_plugin_parameter_addon addon);
   111 int DeactivateSpoofFilter(void);
   112 void RestoreSpoofFilter(void);
   113 
   114 #define MAX_UNICAST_NEIGHBORS 10
   115 struct TBestNeighbors
   116 {
   117   struct link_entry* links[MAX_UNICAST_NEIGHBORS];
   118 };
   119 
   120 void FindNeighbors(
   121   struct TBestNeighbors* neighbors,
   122   struct link_entry** bestNeighbor,
   123   struct TBmfInterface* intf,
   124   union olsr_ip_addr* source,
   125   union olsr_ip_addr* forwardedBy,
   126   union olsr_ip_addr* forwardedTo,
   127   int* nPossibleNeighbors);
   128 
   129 int CreateBmfNetworkInterfaces(struct interface* skipThisIntf);
   130 void AddInterface(struct interface* newIntf);
   131 void CloseBmfNetworkInterfaces(void);
   132 int AddNonOlsrBmfIf(const char* ifName, void* data, set_plugin_parameter_addon addon);
   133 int IsNonOlsrBmfIf(const char* ifName);
   134 void CheckAndUpdateLocalBroadcast(unsigned char* ipPacket, union olsr_ip_addr* broadAddr);
   135 void AddMulticastRoute(void);
   136 void DeleteMulticastRoute(void);
   137 
   138 #endif /* _BMF_NETWORKINTERFACES_H */
   139 
   140 /*
   141  * Local Variables:
   142  * c-basic-offset: 2
   143  * indent-tabs-mode: nil
   144  * End:
   145  */