1 /*
2  * The olsr.org Optimized Link-State Routing daemon (olsrd)
3  *
4  * (c) by the OLSR project
5  *
6  * See our Git repository to find out who worked on this file
7  * and thus is a copyright holder on it.
8  *
9  * All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  *
15  * * Redistributions of source code must retain the above copyright
16  *   notice, this list of conditions and the following disclaimer.
17  * * Redistributions in binary form must reproduce the above copyright
18  *   notice, this list of conditions and the following disclaimer in
19  *   the documentation and/or other materials provided with the
20  *   distribution.
21  * * Neither the name of olsr.org, olsrd nor the names of its
22  *   contributors may be used to endorse or promote products derived
23  *   from this software without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
28  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
29  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
30  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
31  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
32  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
33  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
35  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36  * POSSIBILITY OF SUCH DAMAGE.
37  *
38  * Visit http://www.olsr.org for more information.
39  *
40  * If you find this software useful feel free to make a donation
41  * to the project. For more information see the website or contact
42  * the copyright holders.
43  *
44  */
45 
46 
47 #ifndef _P2PD_NETWORKINTERFACES_H
48 #define _P2PD_NETWORKINTERFACES_H
49 
50 /* System includes */
51 #include <netinet/in.h>         /* struct in_addr */
52 
53 /* OLSR includes */
54 #include "olsr_types.h"         /* olsr_ip_addr */
55 #include "olsrd_plugin.h"             /* union set_plugin_parameter_addon */
56 
57 /* Plugin includes */
58 #include "Packet.h"             /* IFHWADDRLEN */
59 #include "p2pd.h"
60 
61 /* Size of buffer in which packets are received */
62 #define P2PD_BUFFER_SIZE 2048
63 
64 struct NonOlsrInterface {
65   /* File descriptor of raw packet socket, used for capturing multicast packets */
66   int capturingSkfd;
67 
68   /* File descriptor of UDP (datagram) socket for encapsulated multicast packets.
69    * Only used for OLSR-enabled interfaces; set to -1 if interface is not OLSR-enabled. */
70   int encapsulatingSkfd;
71 
72   /* File descriptor of UDP packet socket, used for listening to encapsulation packets.
73    * Used only when PlParam "P2pdMechanism" is set to "UnicastPromiscuous". */
74   int listeningSkfd;
75 
76   unsigned char macAddr[IFHWADDRLEN];
77 
78   char ifName[IFNAMSIZ];
79 
80   /* OLSRs idea of this network interface. NULL if this interface is not
81    * OLSR-enabled. */
82   struct interface_olsr *olsrIntf;
83 
84   /* IP address of this network interface */
85   union olsr_ip_addr intAddr;
86 
87   /* Broadcast address of this network interface */
88   union olsr_ip_addr broadAddr;
89 
90 #define FRAGMENT_HISTORY_SIZE 10
91   struct TFragmentHistory {
92     u_int16_t ipId;
93     u_int8_t ipProto;
94     struct in_addr ipSrc;
95     struct in_addr ipDst;
96   } fragmentHistory[FRAGMENT_HISTORY_SIZE];
97 
98   int nextFragmentHistoryEntry;
99 
100   /* Number of received and transmitted BMF packets on this interface */
101   u_int32_t nPacketsRx;
102   u_int32_t nPacketsRxDup;
103   u_int32_t nPacketsTx;
104 
105   /* Next element in list */
106   struct NonOlsrInterface *next;
107 };
108 
109 extern struct NonOlsrInterface *nonOlsrInterfaces;
110 
111 extern int HighestSkfd;
112 extern fd_set InputSet;
113 
114 extern int EtherTunTapFd;
115 
116 extern char EtherTunTapIfName[];
117 
118 /* 10.255.255.253 in host byte order */
119 #define ETHERTUNTAPDEFAULTIP 0x0AFFFFFD
120 
121 extern u_int32_t EtherTunTapIp;
122 extern u_int32_t EtherTunTapIpMask;
123 extern u_int32_t EtherTunTapIpBroadcast;
124 
125 
126 enum P2pdMechanism { BM_BROADCAST = 0, BM_UNICAST_PROMISCUOUS };
127 extern enum P2pdMechanism P2pdMechanism;
128 
129 int SetNonOlsrInterfaceName(const char *ifname, void *data, set_plugin_parameter_addon addon);
130 int SetNonOlsrInterfaceIp(const char *ip, void *data, set_plugin_parameter_addon addon);
131 int SetCapturePacketsOnOlsrInterfaces(const char *enable, void *data, set_plugin_parameter_addon addon);
132 int SetP2pdMechanism(const char *mechanism, void *data, set_plugin_parameter_addon addon);
133 int DeactivateSpoofFilter(void);
134 void RestoreSpoofFilter(void);
135 
136 #define MAX_UNICAST_NEIGHBORS 10
137 struct TBestNeighbors {
138   struct link_entry *links[MAX_UNICAST_NEIGHBORS];
139 };
140 
141 void FindNeighbors(struct TBestNeighbors *neighbors,
142                    struct link_entry **bestNeighbor,
143                    struct NonOlsrInterface *intf,
144                    union olsr_ip_addr *source,
145                    union olsr_ip_addr *forwardedBy, union olsr_ip_addr *forwardedTo, int *nPossibleNeighbors);
146 
147 int CreateNonOlsrNetworkInterfaces(struct interface_olsr *skipThisIntf);
148 void AddInterface(struct interface_olsr *newIntf);
149 void CloseNonOlsrNetworkInterfaces(void);
150 int AddNonOlsrIf(const char *ifName, void *data, set_plugin_parameter_addon addon);
151 int IsNonOlsrIf(const char *ifName);
152 void CheckAndUpdateLocalBroadcast(unsigned char *ipPacket, union olsr_ip_addr *broadAddr);
153 void AddMulticastRoute(void);
154 void DeleteMulticastRoute(void);
155 int CreateCaptureSocket(const char *ifName);
156 
157 #endif /* _P2PD_NETWORKINTERFACES_H */
158 
159 /*
160  * Local Variables:
161  * c-basic-offset: 2
162  * indent-tabs-mode: nil
163  * End:
164  */
165