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