VirtualBox

source: vbox/trunk/src/VBox/NetworkServices/NAT/VBoxNetLwipNAT.cpp@ 49836

Last change on this file since 49836 was 49836, checked in by vboxsync, 11 years ago

VBoxNetLwipNAT.cpp: extract fetchNatPortForwardRules() to fetch ipv4 and ipv6 port-forward-rules.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 35.8 KB
Line 
1/* $Id: VBoxNetLwipNAT.cpp 49836 2013-12-09 11:50:26Z vboxsync $ */
2/** @file
3 * VBoxNetNAT - NAT Service for connecting to IntNet.
4 */
5
6/*
7 * Copyright (C) 2009 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18#include "winutils.h"
19
20#include <VBox/com/com.h>
21#include <VBox/com/listeners.h>
22#include <VBox/com/string.h>
23#include <VBox/com/Guid.h>
24#include <VBox/com/array.h>
25#include <VBox/com/ErrorInfo.h>
26#include <VBox/com/errorprint.h>
27#include <VBox/com/VirtualBox.h>
28#include <VBox/com/NativeEventQueue.h>
29
30#include <iprt/net.h>
31#include <iprt/initterm.h>
32#include <iprt/alloca.h>
33#ifndef RT_OS_WINDOWS
34# include <arpa/inet.h>
35#endif
36#include <iprt/err.h>
37#include <iprt/time.h>
38#include <iprt/timer.h>
39#include <iprt/thread.h>
40#include <iprt/stream.h>
41#include <iprt/path.h>
42#include <iprt/param.h>
43#include <iprt/pipe.h>
44#include <iprt/getopt.h>
45#include <iprt/string.h>
46#include <iprt/mem.h>
47#include <iprt/message.h>
48#include <iprt/req.h>
49#include <iprt/file.h>
50#include <iprt/semaphore.h>
51#include <iprt/cpp/utils.h>
52#define LOG_GROUP LOG_GROUP_NAT_SERVICE
53#include <VBox/log.h>
54
55#include <VBox/sup.h>
56#include <VBox/intnet.h>
57#include <VBox/intnetinline.h>
58#include <VBox/vmm/pdmnetinline.h>
59#include <VBox/vmm/vmm.h>
60#include <VBox/version.h>
61
62#ifndef RT_OS_WINDOWS
63# include <sys/poll.h>
64# include <sys/socket.h>
65# include <netinet/in.h>
66# ifdef RT_OS_LINUX
67# include <linux/icmp.h> /* ICMP_FILTER */
68# endif
69# include <netinet/icmp6.h>
70#endif
71
72#include <map>
73#include <vector>
74#include <string>
75
76#include "../NetLib/VBoxNetLib.h"
77#include "../NetLib/VBoxNetBaseService.h"
78#include "../NetLib/utils.h"
79#include "VBoxLwipCore.h"
80
81extern "C"
82{
83/* bunch of LWIP headers */
84#include "lwip/opt.h"
85#ifdef LWIP_SOCKET
86# undef LWIP_SOCKET
87# define LWIP_SOCKET 0
88#endif
89#include "lwip/sys.h"
90#include "lwip/pbuf.h"
91#include "lwip/netif.h"
92#include "lwip/ethip6.h"
93#include "lwip/nd6.h" // for proxy_na_hook
94#include "lwip/mld6.h"
95#include "lwip/tcpip.h"
96#include "netif/etharp.h"
97
98#include "proxy.h"
99#include "pxremap.h"
100#include "portfwd.h"
101}
102
103#include "../NetLib/VBoxPortForwardString.h"
104
105static RTGETOPTDEF g_aGetOptDef[] =
106{
107 { "--port-forward4", 'p', RTGETOPT_REQ_STRING },
108 { "--port-forward6", 'P', RTGETOPT_REQ_STRING }
109};
110
111typedef struct NATSEVICEPORTFORWARDRULE
112{
113 PORTFORWARDRULE Pfr;
114 fwspec FWSpec;
115} NATSEVICEPORTFORWARDRULE, *PNATSEVICEPORTFORWARDRULE;
116
117typedef std::vector<NATSEVICEPORTFORWARDRULE> VECNATSERVICEPF;
118typedef VECNATSERVICEPF::iterator ITERATORNATSERVICEPF;
119typedef VECNATSERVICEPF::const_iterator CITERATORNATSERVICEPF;
120
121static int fetchNatPortForwardRules(const ComNatPtr&, bool, VECNATSERVICEPF&);
122
123
124class VBoxNetLwipNAT: public VBoxNetBaseService, public NATNetworkEventAdapter
125{
126 friend class NATNetworkListener;
127 public:
128 VBoxNetLwipNAT(SOCKET icmpsock4, SOCKET icmpsock6);
129 virtual ~VBoxNetLwipNAT();
130 void usage(){ /* @todo: should be implemented */ };
131 int run();
132 virtual int init(void);
133 /* @todo: when configuration would be really needed */
134 virtual int parseOpt(int rc, const RTGETOPTUNION& getOptVal);
135 /* VBoxNetNAT always needs Main */
136 virtual bool isMainNeeded() const { return true; }
137 virtual int processFrame(void *, size_t);
138 virtual int processGSO(PCPDMNETWORKGSO, size_t);
139 virtual int processUDP(void *, size_t) { return VERR_IGNORED; }
140
141 private:
142 struct proxy_options m_ProxyOptions;
143 struct sockaddr_in m_src4;
144 struct sockaddr_in6 m_src6;
145 /**
146 * place for registered local interfaces.
147 */
148 ip4_lomap m_lo2off[10];
149 ip4_lomap_desc m_loOptDescriptor;
150
151 uint16_t m_u16Mtu;
152 netif m_LwipNetIf;
153 /* thread where we're waiting for a frames, no semaphores needed */
154 RTTHREAD hThrIntNetRecv;
155
156 /* Our NAT network descriptor in Main */
157 ComPtr<INATNetwork> m_net;
158 ComNatListenerPtr m_listener;
159
160 ComPtr<IHost> m_host;
161 ComNatListenerPtr m_vboxListener;
162 static INTNETSEG aXmitSeg[64];
163
164 HRESULT HandleEvent(VBoxEventType_T aEventType, IEvent *pEvent);
165
166 const char **getHostNameservers();
167
168 /* Only for debug needs, by default NAT service should load rules from SVC
169 * on startup, and then on sync them on events.
170 */
171 bool fDontLoadRulesOnStartup;
172 static void onLwipTcpIpInit(void *arg);
173 static void onLwipTcpIpFini(void *arg);
174 static err_t netifInit(netif *pNetif);
175 static err_t netifLinkoutput(netif *pNetif, pbuf *pBuf);
176 static int intNetThreadRecv(RTTHREAD, void *);
177
178 VECNATSERVICEPF m_vecPortForwardRule4;
179 VECNATSERVICEPF m_vecPortForwardRule6;
180
181 static int natServicePfRegister(NATSEVICEPORTFORWARDRULE& natServicePf);
182 static int natServiceProcessRegisteredPf(VECNATSERVICEPF& vecPf);
183};
184
185
186static VBoxNetLwipNAT *g_pLwipNat;
187INTNETSEG VBoxNetLwipNAT::aXmitSeg[64];
188
189STDMETHODIMP VBoxNetLwipNAT::HandleEvent(VBoxEventType_T aEventType,
190 IEvent *pEvent)
191{
192 HRESULT hrc = S_OK;
193 switch (aEventType)
194 {
195 case VBoxEventType_OnNATNetworkSetting:
196 {
197 ComPtr<INATNetworkSettingEvent> evSettings(pEvent);
198 // XXX: only handle IPv6 default route for now
199
200 if (!m_ProxyOptions.ipv6_enabled)
201 {
202 break;
203 }
204
205 BOOL fIPv6DefaultRoute = FALSE;
206 hrc = evSettings->COMGETTER(AdvertiseDefaultIPv6RouteEnabled)(&fIPv6DefaultRoute);
207 AssertReturn(SUCCEEDED(hrc), hrc);
208
209 if (m_ProxyOptions.ipv6_defroute == fIPv6DefaultRoute)
210 {
211 break;
212 }
213
214 m_ProxyOptions.ipv6_defroute = fIPv6DefaultRoute;
215 tcpip_callback_with_block(proxy_rtadvd_do_quick, &m_LwipNetIf, 0);
216
217 break;
218 }
219
220 case VBoxEventType_OnNATNetworkPortForward:
221 {
222 com::Bstr name, strHostAddr, strGuestAddr;
223 LONG lHostPort, lGuestPort;
224 BOOL fCreateFW, fIPv6FW;
225 NATProtocol_T proto = NATProtocol_TCP;
226
227
228 ComPtr<INATNetworkPortForwardEvent> pfEvt = pEvent;
229
230 hrc = pfEvt->COMGETTER(Name)(name.asOutParam());
231 AssertReturn(SUCCEEDED(hrc), hrc);
232
233 hrc = pfEvt->COMGETTER(Proto)(&proto);
234 AssertReturn(SUCCEEDED(hrc), hrc);
235
236 hrc = pfEvt->COMGETTER(HostIp)(strHostAddr.asOutParam());
237 AssertReturn(SUCCEEDED(hrc), hrc);
238
239 hrc = pfEvt->COMGETTER(HostPort)(&lHostPort);
240 AssertReturn(SUCCEEDED(hrc), hrc);
241
242 hrc = pfEvt->COMGETTER(GuestIp)(strGuestAddr.asOutParam());
243 AssertReturn(SUCCEEDED(hrc), hrc);
244
245 hrc = pfEvt->COMGETTER(GuestPort)(&lGuestPort);
246 AssertReturn(SUCCEEDED(hrc), hrc);
247
248 hrc = pfEvt->COMGETTER(Create)(&fCreateFW);
249 AssertReturn(SUCCEEDED(hrc), hrc);
250
251 hrc = pfEvt->COMGETTER(Ipv6)(&fIPv6FW);
252 AssertReturn(SUCCEEDED(hrc), hrc);
253
254 VECNATSERVICEPF& rules = (fIPv6FW ?
255 m_vecPortForwardRule6 :
256 m_vecPortForwardRule4);
257
258 NATSEVICEPORTFORWARDRULE r;
259
260 RT_ZERO(r);
261
262 if (name.length() > sizeof(r.Pfr.szPfrName))
263 {
264 hrc = E_INVALIDARG;
265 goto port_forward_done;
266 }
267
268 r.Pfr.fPfrIPv6 = fIPv6FW;
269
270 switch (proto)
271 {
272 case NATProtocol_TCP:
273 r.Pfr.iPfrProto = IPPROTO_TCP;
274 break;
275 case NATProtocol_UDP:
276 r.Pfr.iPfrProto = IPPROTO_UDP;
277 break;
278 default:
279 goto port_forward_done;
280 }
281
282
283 RTStrPrintf(r.Pfr.szPfrName, sizeof(r.Pfr.szPfrName),
284 "%s", com::Utf8Str(name).c_str());
285
286 RTStrPrintf(r.Pfr.szPfrHostAddr, sizeof(r.Pfr.szPfrHostAddr),
287 "%s", com::Utf8Str(strHostAddr).c_str());
288
289 /* XXX: limits should be checked */
290 r.Pfr.u16PfrHostPort = (uint16_t)lHostPort;
291
292 RTStrPrintf(r.Pfr.szPfrGuestAddr, sizeof(r.Pfr.szPfrGuestAddr),
293 "%s", com::Utf8Str(strGuestAddr).c_str());
294
295 /* XXX: limits should be checked */
296 r.Pfr.u16PfrGuestPort = (uint16_t)lGuestPort;
297
298 if (fCreateFW) /* Addition */
299 {
300 rules.push_back(r);
301
302 natServicePfRegister(rules.back());
303 }
304 else /* Deletion */
305 {
306 ITERATORNATSERVICEPF it;
307 for (it = rules.begin(); it != rules.end(); ++it)
308 {
309 /* compare */
310 NATSEVICEPORTFORWARDRULE& natFw = *it;
311 if ( natFw.Pfr.iPfrProto == r.Pfr.iPfrProto
312 && natFw.Pfr.u16PfrHostPort == r.Pfr.u16PfrHostPort
313 && (strncmp(natFw.Pfr.szPfrHostAddr, r.Pfr.szPfrHostAddr, INET6_ADDRSTRLEN) == 0)
314 && natFw.Pfr.u16PfrGuestPort == r.Pfr.u16PfrGuestPort
315 && (strncmp(natFw.Pfr.szPfrGuestAddr, r.Pfr.szPfrGuestAddr, INET6_ADDRSTRLEN) == 0))
316 {
317 fwspec *pFwCopy = (fwspec *)RTMemAllocZ(sizeof(fwspec));
318 if (!pFwCopy)
319 {
320 break;
321 }
322 memcpy(pFwCopy, &natFw.FWSpec, sizeof(fwspec));
323
324 /* We shouldn't care about pFwCopy this memory will be freed when
325 * will message will arrive to the destination.
326 */
327 portfwd_rule_del(pFwCopy);
328
329 rules.erase(it);
330 break;
331 }
332 } /* loop over vector elements */
333 } /* condition add or delete */
334 port_forward_done:
335 /* clean up strings */
336 name.setNull();
337 strHostAddr.setNull();
338 strGuestAddr.setNull();
339 break;
340 }
341
342 case VBoxEventType_OnHostNameResolutionConfigurationChange:
343 {
344 const char **ppcszNameServers = getHostNameservers();
345 err_t error;
346
347 error = tcpip_callback_with_block(pxdns_set_nameservers,
348 ppcszNameServers,
349 /* :block */ 0);
350 if (error != ERR_OK && ppcszNameServers != NULL)
351 {
352 RTMemFree(ppcszNameServers);
353 }
354 break;
355 }
356 }
357 return hrc;
358}
359
360
361void VBoxNetLwipNAT::onLwipTcpIpInit(void* arg)
362{
363 AssertPtrReturnVoid(arg);
364 VBoxNetLwipNAT *pNat = static_cast<VBoxNetLwipNAT *>(arg);
365
366 HRESULT hrc = com::Initialize();
367 Assert(!FAILED(hrc));
368
369 proxy_arp_hook = pxremap_proxy_arp;
370 proxy_ip4_divert_hook = pxremap_ip4_divert;
371
372 proxy_na_hook = pxremap_proxy_na;
373 proxy_ip6_divert_hook = pxremap_ip6_divert;
374
375 /* lwip thread */
376 RTNETADDRIPV4 network;
377 RTNETADDRIPV4 address = g_pLwipNat->getIpv4Address();
378 RTNETADDRIPV4 netmask = g_pLwipNat->getIpv4Netmask();
379 network.u = address.u & netmask.u;
380
381 ip_addr LwipIpAddr, LwipIpNetMask, LwipIpNetwork;
382
383 memcpy(&LwipIpAddr, &address, sizeof(ip_addr));
384 memcpy(&LwipIpNetMask, &netmask, sizeof(ip_addr));
385 memcpy(&LwipIpNetwork, &network, sizeof(ip_addr));
386
387 netif *pNetif = netif_add(&g_pLwipNat->m_LwipNetIf /* Lwip Interface */,
388 &LwipIpAddr /* IP address*/,
389 &LwipIpNetMask /* Network mask */,
390 &LwipIpAddr /* gateway address, @todo: is self IP acceptable? */,
391 g_pLwipNat /* state */,
392 VBoxNetLwipNAT::netifInit /* netif_init_fn */,
393 lwip_tcpip_input /* netif_input_fn */);
394
395 AssertPtrReturnVoid(pNetif);
396
397 netif_set_up(pNetif);
398 netif_set_link_up(pNetif);
399
400 if (pNat->m_ProxyOptions.ipv6_enabled) {
401 /*
402 * XXX: lwIP currently only ever calls mld6_joingroup() in
403 * nd6_tmr() for fresh tentative addresses, which is a wrong place
404 * to do it - but I'm not keen on fixing this properly for now
405 * (with correct handling of interface up and down transitions,
406 * etc). So stick it here as a kludge.
407 */
408 for (int i = 0; i <= 1; ++i) {
409 ip6_addr_t *paddr = netif_ip6_addr(pNetif, i);
410
411 ip6_addr_t solicited_node_multicast_address;
412 ip6_addr_set_solicitednode(&solicited_node_multicast_address,
413 paddr->addr[3]);
414 mld6_joingroup(paddr, &solicited_node_multicast_address);
415 }
416
417 /*
418 * XXX: We must join the solicited-node multicast for the
419 * addresses we do IPv6 NA-proxy for. We map IPv6 loopback to
420 * proxy address + 1. We only need the low 24 bits, and those are
421 * fixed.
422 */
423 {
424 ip6_addr_t solicited_node_multicast_address;
425
426 ip6_addr_set_solicitednode(&solicited_node_multicast_address,
427 /* last 24 bits of the address */
428 PP_HTONL(0x00000002));
429 mld6_netif_joingroup(pNetif, &solicited_node_multicast_address);
430 }
431 }
432
433 proxy_init(&g_pLwipNat->m_LwipNetIf, &g_pLwipNat->m_ProxyOptions);
434
435 natServiceProcessRegisteredPf(g_pLwipNat->m_vecPortForwardRule4);
436 natServiceProcessRegisteredPf(g_pLwipNat->m_vecPortForwardRule6);
437}
438
439
440void VBoxNetLwipNAT::onLwipTcpIpFini(void* arg)
441{
442 AssertPtrReturnVoid(arg);
443 VBoxNetLwipNAT *pThis = (VBoxNetLwipNAT *)arg;
444
445 /* XXX: proxy finalization */
446 netif_set_link_down(&g_pLwipNat->m_LwipNetIf);
447 netif_set_down(&g_pLwipNat->m_LwipNetIf);
448 netif_remove(&g_pLwipNat->m_LwipNetIf);
449
450}
451
452/*
453 * Callback for netif_add() to initialize the interface.
454 */
455err_t VBoxNetLwipNAT::netifInit(netif *pNetif)
456{
457 err_t rcLwip = ERR_OK;
458
459 AssertPtrReturn(pNetif, ERR_ARG);
460
461 VBoxNetLwipNAT *pNat = static_cast<VBoxNetLwipNAT *>(pNetif->state);
462 AssertPtrReturn(pNat, ERR_ARG);
463
464 LogFlowFunc(("ENTER: pNetif[%c%c%d]\n", pNetif->name[0], pNetif->name[1], pNetif->num));
465 /* validity */
466 AssertReturn( pNetif->name[0] == 'N'
467 && pNetif->name[1] == 'T', ERR_ARG);
468
469
470 pNetif->hwaddr_len = sizeof(RTMAC);
471 RTMAC mac = g_pLwipNat->getMacAddress();
472 memcpy(pNetif->hwaddr, &mac, sizeof(RTMAC));
473
474 pNat->m_u16Mtu = 1500; // XXX: FIXME
475 pNetif->mtu = pNat->m_u16Mtu;
476
477 pNetif->flags = NETIF_FLAG_BROADCAST
478 | NETIF_FLAG_ETHARP /* Don't bother driver with ARP and let Lwip resolve ARP handling */
479 | NETIF_FLAG_ETHERNET; /* Lwip works with ethernet too */
480
481 pNetif->linkoutput = netifLinkoutput; /* ether-level-pipe */
482 pNetif->output = lwip_etharp_output; /* ip-pipe */
483
484 if (pNat->m_ProxyOptions.ipv6_enabled) {
485 pNetif->output_ip6 = ethip6_output;
486
487 /* IPv6 link-local address in slot 0 */
488 netif_create_ip6_linklocal_address(pNetif, /* :from_mac_48bit */ 1);
489 netif_ip6_addr_set_state(pNetif, 0, IP6_ADDR_PREFERRED); // skip DAD
490
491 /*
492 * RFC 4193 Locally Assigned Global ID (ULA) in slot 1
493 * [fd17:625c:f037:XXXX::1] where XXXX, 16 bit Subnet ID, are two
494 * bytes from the middle of the IPv4 address, e.g. :dead: for
495 * 10.222.173.1
496 */
497 u8_t nethi = ip4_addr2(&pNetif->ip_addr);
498 u8_t netlo = ip4_addr3(&pNetif->ip_addr);
499
500 ip6_addr_t *paddr = netif_ip6_addr(pNetif, 1);
501 IP6_ADDR(paddr, 0, 0xFD, 0x17, 0x62, 0x5C);
502 IP6_ADDR(paddr, 1, 0xF0, 0x37, nethi, netlo);
503 IP6_ADDR(paddr, 2, 0x00, 0x00, 0x00, 0x00);
504 IP6_ADDR(paddr, 3, 0x00, 0x00, 0x00, 0x01);
505 netif_ip6_addr_set_state(pNetif, 1, IP6_ADDR_PREFERRED);
506
507#if LWIP_IPV6_SEND_ROUTER_SOLICIT
508 pNetif->rs_count = 0;
509#endif
510 }
511
512 LogFlowFunc(("LEAVE: %d\n", rcLwip));
513 return rcLwip;
514}
515
516
517/**
518 * Intnet-recv thread
519 */
520int VBoxNetLwipNAT::intNetThreadRecv(RTTHREAD, void *)
521{
522 int rc = VINF_SUCCESS;
523
524 /* 1. initialization and connection */
525 HRESULT hrc = com::Initialize();
526 if (FAILED(hrc))
527 return RTMsgErrorExit(RTEXITCODE_FAILURE, "Failed to initialize COM!");
528
529 g_pLwipNat->doReceiveLoop();
530 /* 3. deinitilization and termination */
531 LogFlowFuncLeaveRC(rc);
532 return rc;
533}
534
535
536err_t VBoxNetLwipNAT::netifLinkoutput(netif *pNetif, pbuf *pPBuf)
537{
538 AssertPtrReturn(pNetif, ERR_ARG);
539 AssertPtrReturn(pPBuf, ERR_ARG);
540 AssertReturn((void *)g_pLwipNat == pNetif->state, ERR_ARG);
541
542 LogFlowFunc(("ENTER: pNetif[%c%c%d], pPbuf:%p\n",
543 pNetif->name[0],
544 pNetif->name[1],
545 pNetif->num,
546 pPBuf));
547
548 RT_ZERO(VBoxNetLwipNAT::aXmitSeg);
549
550 unsigned idx = 0;
551 for( struct pbuf *pPBufPtr = pPBuf;
552 pPBufPtr;
553 pPBufPtr = pPBufPtr->next, ++idx)
554 {
555 AssertReturn(idx < RT_ELEMENTS(VBoxNetLwipNAT::aXmitSeg), ERR_MEM);
556 VBoxNetLwipNAT::aXmitSeg[idx].pv = pPBufPtr->payload;
557 VBoxNetLwipNAT::aXmitSeg[idx].cb = pPBufPtr->len;
558 }
559
560 int rc = g_pLwipNat->sendBufferOnWire(VBoxNetLwipNAT::aXmitSeg, idx, pPBuf->tot_len);
561 AssertRCReturn(rc, ERR_IF);
562
563 g_pLwipNat->flushWire();
564
565 LogFlowFunc(("LEAVE: %d\n", ERR_OK));
566 return ERR_OK;
567}
568
569
570VBoxNetLwipNAT::VBoxNetLwipNAT(SOCKET icmpsock4, SOCKET icmpsock6) : VBoxNetBaseService("VBoxNetNAT", "nat-network")
571{
572 LogFlowFuncEnter();
573
574 m_ProxyOptions.ipv6_enabled = 0;
575 m_ProxyOptions.ipv6_defroute = 0;
576 m_ProxyOptions.icmpsock4 = icmpsock4;
577 m_ProxyOptions.icmpsock6 = icmpsock6;
578 m_ProxyOptions.tftp_root = NULL;
579 m_ProxyOptions.src4 = NULL;
580 m_ProxyOptions.src6 = NULL;
581 memset(&m_src4, 0, sizeof(m_src4));
582 memset(&m_src6, 0, sizeof(m_src6));
583 m_src4.sin_family = AF_INET;
584 m_src6.sin6_family = AF_INET6;
585#if HAVE_SA_LEN
586 m_src4.sin_len = sizeof(m_src4);
587 m_src6.sin6_len = sizeof(m_src6);
588#endif
589 m_ProxyOptions.nameservers = NULL;
590
591 m_LwipNetIf.name[0] = 'N';
592 m_LwipNetIf.name[1] = 'T';
593
594 RTMAC mac;
595 mac.au8[0] = 0x52;
596 mac.au8[1] = 0x54;
597 mac.au8[2] = 0;
598 mac.au8[3] = 0x12;
599 mac.au8[4] = 0x35;
600 mac.au8[5] = 0;
601 setMacAddress(mac);
602
603 RTNETADDRIPV4 address;
604 address.u = RT_MAKE_U32_FROM_U8( 10, 0, 2, 2); // NB: big-endian
605 setIpv4Address(address);
606
607 address.u = RT_H2N_U32_C(0xffffff00);
608 setIpv4Netmask(address);
609
610 fDontLoadRulesOnStartup = false;
611
612 for(unsigned int i = 0; i < RT_ELEMENTS(g_aGetOptDef); ++i)
613 addCommandLineOption(&g_aGetOptDef[i]);
614
615 LogFlowFuncLeave();
616}
617
618
619VBoxNetLwipNAT::~VBoxNetLwipNAT()
620{
621 if (m_ProxyOptions.tftp_root != NULL)
622 {
623 RTStrFree((char *)m_ProxyOptions.tftp_root);
624 }
625}
626
627
628int VBoxNetLwipNAT::natServicePfRegister(NATSEVICEPORTFORWARDRULE& natPf)
629{
630 int lrc = 0;
631 int rc = VINF_SUCCESS;
632 int socketSpec = SOCK_STREAM;
633 char *pszHostAddr;
634 int sockFamily = (natPf.Pfr.fPfrIPv6 ? PF_INET6 : PF_INET);
635
636 switch(natPf.Pfr.iPfrProto)
637 {
638 case IPPROTO_TCP:
639 socketSpec = SOCK_STREAM;
640 break;
641 case IPPROTO_UDP:
642 socketSpec = SOCK_DGRAM;
643 break;
644 default:
645 return VERR_IGNORED; /* Ah, just ignore the garbage */
646 }
647
648 pszHostAddr = natPf.Pfr.szPfrHostAddr;
649
650 /* XXX: workaround for inet_pton and an empty ipv4 address
651 * in rule declaration.
652 */
653 if ( sockFamily == PF_INET
654 && pszHostAddr[0] == 0)
655 pszHostAddr = (char *)"0.0.0.0"; /* XXX: fix it! without type cast */
656
657
658 lrc = fwspec_set(&natPf.FWSpec,
659 sockFamily,
660 socketSpec,
661 pszHostAddr,
662 natPf.Pfr.u16PfrHostPort,
663 natPf.Pfr.szPfrGuestAddr,
664 natPf.Pfr.u16PfrGuestPort);
665
666 AssertReturn(!lrc, VERR_IGNORED);
667
668 fwspec *pFwCopy = (fwspec *)RTMemAllocZ(sizeof(fwspec));
669 AssertPtrReturn(pFwCopy, VERR_IGNORED);
670
671 /*
672 * We need pass the copy, because we can't be sure
673 * how much this pointer will be valid in LWIP environment.
674 */
675 memcpy(pFwCopy, &natPf.FWSpec, sizeof(fwspec));
676
677 lrc = portfwd_rule_add(pFwCopy);
678
679 AssertReturn(!lrc, VERR_IGNORED);
680
681 return VINF_SUCCESS;
682}
683
684
685int VBoxNetLwipNAT::natServiceProcessRegisteredPf(VECNATSERVICEPF& vecRules){
686 ITERATORNATSERVICEPF it;
687 for (it = vecRules.begin();
688 it != vecRules.end(); ++it)
689 {
690 int rc = natServicePfRegister((*it));
691 if (RT_FAILURE(rc))
692 {
693 LogRel(("PF: %s is ignored\n", (*it).Pfr.szPfrName));
694 continue;
695 }
696 }
697 return VINF_SUCCESS;
698}
699
700
701int VBoxNetLwipNAT::init()
702{
703 LogFlowFuncEnter();
704
705 /* virtualbox initialized in super class */
706 int rc = ::VBoxNetBaseService::init();
707 AssertRCReturn(rc, rc);
708
709 std::string networkName = getNetwork();
710 rc = findNatNetwork(virtualbox, networkName, m_net);
711 AssertRCReturn(rc, rc);
712
713 ComEventTypeArray aNetEvents;
714 aNetEvents.push_back(VBoxEventType_OnNATNetworkPortForward);
715 aNetEvents.push_back(VBoxEventType_OnNATNetworkSetting);
716 rc = createNatListener(m_listener, virtualbox, this, aNetEvents);
717 AssertRCReturn(rc, rc);
718
719
720 // resolver changes are reported on vbox but are retrieved from
721 // host so stash a pointer for future lookups
722 HRESULT hrc = virtualbox->COMGETTER(Host)(m_host.asOutParam());
723 AssertComRCReturn(hrc, VERR_INTERNAL_ERROR);
724
725 ComEventTypeArray aVBoxEvents;
726 aVBoxEvents.push_back(VBoxEventType_OnHostNameResolutionConfigurationChange);
727 rc = createNatListener(m_vboxListener, virtualbox, this, aVBoxEvents);
728 AssertRCReturn(rc, rc);
729
730 BOOL fIPv6Enabled = FALSE;
731 hrc = m_net->COMGETTER(IPv6Enabled)(&fIPv6Enabled);
732 AssertComRCReturn(hrc, VERR_NOT_FOUND);
733
734 BOOL fIPv6DefaultRoute = FALSE;
735 if (fIPv6Enabled)
736 {
737 hrc = m_net->COMGETTER(AdvertiseDefaultIPv6RouteEnabled)(&fIPv6DefaultRoute);
738 AssertComRCReturn(hrc, VERR_NOT_FOUND);
739 }
740
741 m_ProxyOptions.ipv6_enabled = fIPv6Enabled;
742 m_ProxyOptions.ipv6_defroute = fIPv6DefaultRoute;
743
744
745 com::Bstr bstrSourceIp4Key = com::BstrFmt("NAT/%s/SourceIp4", networkName.c_str());
746 com::Bstr bstrSourceIpX;
747 hrc = virtualbox->GetExtraData(bstrSourceIp4Key.raw(), bstrSourceIpX.asOutParam());
748 if (SUCCEEDED(hrc))
749 {
750 RTNETADDRIPV4 addr;
751 rc = RTNetStrToIPv4Addr(com::Utf8Str(bstrSourceIpX).c_str(), &addr);
752 if (RT_SUCCESS(rc))
753 {
754 RT_ZERO(m_src4);
755
756 m_src4.sin_addr.s_addr = addr.u;
757 m_ProxyOptions.src4 = &m_src4;
758
759 bstrSourceIpX.setNull();
760 }
761 }
762
763 if (!fDontLoadRulesOnStartup)
764 {
765 fetchNatPortForwardRules(m_net, false, m_vecPortForwardRule4);
766 fetchNatPortForwardRules(m_net, true, m_vecPortForwardRule6);
767 } /* if (!fDontLoadRulesOnStartup) */
768
769 AddressToOffsetMapping tmp;
770 rc = localMappings(m_net, tmp);
771 if (RT_SUCCESS(rc) && tmp.size() != 0)
772 {
773 unsigned long i = 0;
774 for (AddressToOffsetMapping::iterator it = tmp.begin();
775 it != tmp.begin() && i < RT_ELEMENTS(m_lo2off);
776 ++it, ++i)
777 {
778 ip4_addr_set_u32(&m_lo2off[i].loaddr, it->first.u);
779 m_lo2off[i].off = it->second;
780 }
781
782 m_loOptDescriptor.lomap = m_lo2off;
783 m_loOptDescriptor.num_lomap = i;
784 m_ProxyOptions.lomap_desc = &m_loOptDescriptor;
785 }
786
787 com::Bstr bstr;
788 hrc = virtualbox->COMGETTER(HomeFolder)(bstr.asOutParam());
789 AssertComRCReturn(hrc, VERR_NOT_FOUND);
790 if (!bstr.isEmpty())
791 {
792 com::Utf8Str strTftpRoot(com::Utf8StrFmt("%ls%c%s",
793 bstr.raw(), RTPATH_DELIMITER, "TFTP"));
794 char *pszStrTemp; // avoid const char ** vs char **
795 rc = RTStrUtf8ToCurrentCP(&pszStrTemp, strTftpRoot.c_str());
796 AssertRC(rc);
797 m_ProxyOptions.tftp_root = pszStrTemp;
798 }
799
800 m_ProxyOptions.nameservers = getHostNameservers();
801
802 /* end of COM initialization */
803
804 rc = g_pLwipNat->tryGoOnline();
805 if (RT_FAILURE(rc))
806 {
807 return rc;
808 }
809
810 vboxLwipCoreInitialize(VBoxNetLwipNAT::onLwipTcpIpInit, this);
811
812 rc = RTThreadCreate(&g_pLwipNat->hThrIntNetRecv, /* thread handle*/
813 VBoxNetLwipNAT::intNetThreadRecv, /* routine */
814 NULL, /* user data */
815 128 * _1K, /* stack size */
816 RTTHREADTYPE_IO, /* type */
817 0, /* flags, @todo: waitable ?*/
818 "INTNET-RECV");
819 AssertRCReturn(rc,rc);
820
821
822
823 LogFlowFuncLeaveRC(rc);
824 return rc;
825}
826
827
828const char **VBoxNetLwipNAT::getHostNameservers()
829{
830 HRESULT hrc;
831
832 if (m_host.isNull())
833 {
834 return NULL;
835 }
836
837 com::SafeArray<BSTR> aNameServers;
838 hrc = m_host->COMGETTER(NameServers)(ComSafeArrayAsOutParam(aNameServers));
839 if (FAILED(hrc))
840 {
841 return NULL;
842 }
843
844 const size_t cNameServers = aNameServers.size();
845 if (cNameServers == 0)
846 {
847 return NULL;
848 }
849
850 const char **ppcszNameServers =
851 (const char **)RTMemAllocZ(sizeof(char *) * (cNameServers + 1));
852 if (ppcszNameServers == NULL)
853 {
854 return NULL;
855 }
856
857 size_t idxLast = 0;
858 for (size_t i = 0; i < cNameServers; ++i)
859 {
860 com::Utf8Str strNameServer(aNameServers[i]);
861 ppcszNameServers[idxLast] = RTStrDup(strNameServer.c_str());
862 if (ppcszNameServers[idxLast] != NULL)
863 {
864 ++idxLast;
865 }
866 }
867
868 if (idxLast == 0)
869 {
870 RTMemFree(ppcszNameServers);
871 return NULL;
872 }
873
874 return ppcszNameServers;
875}
876
877
878int VBoxNetLwipNAT::parseOpt(int rc, const RTGETOPTUNION& Val)
879{
880 switch (rc)
881 {
882 case 'p':
883 case 'P':
884 {
885 NATSEVICEPORTFORWARDRULE Rule;
886 VECNATSERVICEPF& rules = (rc == 'P'?
887 m_vecPortForwardRule6
888 : m_vecPortForwardRule4);
889
890 fDontLoadRulesOnStartup = true;
891
892 RT_ZERO(Rule);
893
894 int irc = netPfStrToPf(Val.psz, (rc == 'P'), &Rule.Pfr);
895 rules.push_back(Rule);
896 return VINF_SUCCESS;
897 }
898 default:;
899 }
900 return VERR_NOT_FOUND;
901}
902
903
904int VBoxNetLwipNAT::processFrame(void *pvFrame, size_t cbFrame)
905{
906 AssertReturn(pvFrame && cbFrame, VERR_INVALID_PARAMETER);
907
908 struct pbuf *pPbufHdr, *pPbuf;
909 pPbufHdr = pPbuf = pbuf_alloc(PBUF_RAW, cbFrame, PBUF_POOL);
910
911 AssertMsgReturn(pPbuf, ("NAT: Can't allocate send buffer cbFrame=%u\n", cbFrame), VERR_INTERNAL_ERROR);
912 AssertReturn(pPbufHdr->tot_len == cbFrame, VERR_INTERNAL_ERROR);
913
914 uint8_t *pu8Frame = (uint8_t *)pvFrame;
915 while(pPbuf)
916 {
917 memcpy(pPbuf->payload, pu8Frame, pPbuf->len);
918 pu8Frame += pPbuf->len;
919 pPbuf = pPbuf->next;
920 }
921
922 m_LwipNetIf.input(pPbufHdr, &m_LwipNetIf);
923
924 return VINF_SUCCESS;
925}
926
927
928int VBoxNetLwipNAT::processGSO(PCPDMNETWORKGSO pGso, size_t cbFrame)
929{
930 if (!PDMNetGsoIsValid(pGso, cbFrame,
931 cbFrame - sizeof(PDMNETWORKGSO)))
932 return VERR_INVALID_PARAMETER;
933
934 cbFrame -= sizeof(PDMNETWORKGSO);
935 uint8_t abHdrScratch[256];
936 uint32_t const cSegs = PDMNetGsoCalcSegmentCount(pGso,
937 cbFrame);
938 for (size_t iSeg = 0; iSeg < cSegs; iSeg++)
939 {
940 uint32_t cbSegFrame;
941 void *pvSegFrame =
942 PDMNetGsoCarveSegmentQD(pGso,
943 (uint8_t *)(pGso + 1),
944 cbFrame,
945 abHdrScratch,
946 iSeg,
947 cSegs,
948 &cbSegFrame);
949
950 struct pbuf *pPbuf = pbuf_alloc(PBUF_RAW, cbSegFrame, PBUF_POOL);
951
952 AssertMsgReturn(pPbuf, ("NAT: Can't allocate send buffer cbFrame=%u\n", cbSegFrame), VERR_INTERNAL_ERROR);
953 AssertReturn(!pPbuf->next && pPbuf->len == cbSegFrame, VERR_INTERNAL_ERROR);
954
955 memcpy(pPbuf->payload, pvSegFrame, cbSegFrame);
956 m_LwipNetIf.input(pPbuf, &g_pLwipNat->m_LwipNetIf);
957 }
958
959 return VINF_SUCCESS;
960}
961
962
963int VBoxNetLwipNAT::run()
964{
965 /* EventQueue processing from VBoxHeadless.cpp */
966 com::NativeEventQueue *gEventQ = NULL;
967 gEventQ = com::NativeEventQueue::getMainEventQueue();
968 while(true)
969 {
970 /* XXX:todo: graceful termination */
971 gEventQ->processEventQueue(0);
972 gEventQ->processEventQueue(500);
973 }
974
975 vboxLwipCoreFinalize(VBoxNetLwipNAT::onLwipTcpIpFini, this);
976
977 m_vecPortForwardRule4.clear();
978 m_vecPortForwardRule6.clear();
979
980 return VINF_SUCCESS;
981}
982
983
984/**
985 * Entry point.
986 */
987extern "C" DECLEXPORT(int) TrustedMain(int argc, char **argv, char **envp)
988{
989 LogFlowFuncEnter();
990
991 NOREF(envp);
992
993#ifdef RT_OS_WINDOWS
994 WSADATA wsaData;
995 int err;
996
997 err = WSAStartup(MAKEWORD(2,2), &wsaData);
998 if (err)
999 {
1000 fprintf(stderr, "wsastartup: failed (%d)\n", err);
1001 return 1;
1002 }
1003#endif
1004
1005 SOCKET icmpsock4 = INVALID_SOCKET;
1006 SOCKET icmpsock6 = INVALID_SOCKET;
1007#ifndef RT_OS_DARWIN
1008 const int icmpstype = SOCK_RAW;
1009#else
1010 /* on OS X it's not privileged */
1011 const int icmpstype = SOCK_DGRAM;
1012#endif
1013
1014 icmpsock4 = socket(AF_INET, icmpstype, IPPROTO_ICMP);
1015 if (icmpsock4 == INVALID_SOCKET)
1016 {
1017 perror("IPPROTO_ICMP");
1018 }
1019
1020 if (icmpsock4 != INVALID_SOCKET)
1021 {
1022#ifdef ICMP_FILTER // Linux specific
1023 struct icmp_filter flt = {
1024 ~(uint32_t)(
1025 (1U << ICMP_ECHOREPLY)
1026 | (1U << ICMP_DEST_UNREACH)
1027 | (1U << ICMP_TIME_EXCEEDED)
1028 )
1029 };
1030
1031 int status = setsockopt(icmpsock4, SOL_RAW, ICMP_FILTER,
1032 &flt, sizeof(flt));
1033 if (status < 0)
1034 {
1035 perror("ICMP_FILTER");
1036 }
1037#endif
1038 }
1039
1040 icmpsock6 = socket(AF_INET6, icmpstype, IPPROTO_ICMPV6);
1041 if (icmpsock6 == INVALID_SOCKET)
1042 {
1043 perror("IPPROTO_ICMPV6");
1044 }
1045
1046 if (icmpsock6 != INVALID_SOCKET)
1047 {
1048#ifdef ICMP6_FILTER // Windows doesn't support RFC 3542 API
1049 /*
1050 * XXX: We do this here for now, not in pxping.c, to avoid
1051 * name clashes between lwIP and system headers.
1052 */
1053 struct icmp6_filter flt;
1054 ICMP6_FILTER_SETBLOCKALL(&flt);
1055
1056 ICMP6_FILTER_SETPASS(ICMP6_ECHO_REPLY, &flt);
1057
1058 ICMP6_FILTER_SETPASS(ICMP6_DST_UNREACH, &flt);
1059 ICMP6_FILTER_SETPASS(ICMP6_PACKET_TOO_BIG, &flt);
1060 ICMP6_FILTER_SETPASS(ICMP6_TIME_EXCEEDED, &flt);
1061 ICMP6_FILTER_SETPASS(ICMP6_PARAM_PROB, &flt);
1062
1063 int status = setsockopt(icmpsock6, IPPROTO_ICMPV6, ICMP6_FILTER,
1064 &flt, sizeof(flt));
1065 if (status < 0)
1066 {
1067 perror("ICMP6_FILTER");
1068 }
1069#endif
1070 }
1071
1072 HRESULT hrc = com::Initialize();
1073#ifdef VBOX_WITH_XPCOM
1074 if (hrc == NS_ERROR_FILE_ACCESS_DENIED)
1075 {
1076 char szHome[RTPATH_MAX] = "";
1077 com::GetVBoxUserHomeDirectory(szHome, sizeof(szHome));
1078 return RTMsgErrorExit(RTEXITCODE_FAILURE,
1079 "Failed to initialize COM because the global settings directory '%s' is not accessible!", szHome);
1080 }
1081#endif
1082 if (FAILED(hrc))
1083 return RTMsgErrorExit(RTEXITCODE_FAILURE, "Failed to initialize COM!");
1084
1085 g_pLwipNat = new VBoxNetLwipNAT(icmpsock4, icmpsock6);
1086
1087 Log2(("NAT: initialization\n"));
1088 int rc = g_pLwipNat->parseArgs(argc - 1, argv + 1);
1089 rc = (rc == 0) ? VINF_SUCCESS : VERR_GENERAL_FAILURE; /* XXX: FIXME */
1090
1091 if (RT_SUCCESS(rc))
1092 {
1093 rc = g_pLwipNat->init();
1094 }
1095
1096 if (RT_SUCCESS(rc))
1097 {
1098 g_pLwipNat->run();
1099 }
1100
1101 delete g_pLwipNat;
1102 return 0;
1103}
1104
1105
1106static int fetchNatPortForwardRules(const ComNatPtr& nat, bool fIsIPv6, VECNATSERVICEPF& vec)
1107{
1108 HRESULT hrc;
1109 com::SafeArray<BSTR> rules;
1110 if (fIsIPv6)
1111 hrc = nat->COMGETTER(PortForwardRules6)(ComSafeArrayAsOutParam(rules));
1112 else
1113 hrc = nat->COMGETTER(PortForwardRules4)(ComSafeArrayAsOutParam(rules));
1114 AssertReturn(SUCCEEDED(hrc), VERR_INTERNAL_ERROR);
1115
1116 NATSEVICEPORTFORWARDRULE Rule;
1117 for (size_t idxRules = 0; idxRules < rules.size(); ++idxRules)
1118 {
1119 Log(("%d-%s rule: %ls\n", idxRules, (fIsIPv6 ? "IPv6" : "IPv4"), rules[idxRules]));
1120 RT_ZERO(Rule);
1121
1122 int rc = netPfStrToPf(com::Utf8Str(rules[idxRules]).c_str(), 0, &Rule.Pfr);
1123 if (RT_FAILURE(rc))
1124 continue;
1125
1126 vec.push_back(Rule);
1127 }
1128
1129 return VINF_SUCCESS;
1130}
1131
1132
1133#ifndef VBOX_WITH_HARDENING
1134
1135int main(int argc, char **argv, char **envp)
1136{
1137 int rc = RTR3InitExe(argc, &argv, RTR3INIT_FLAGS_SUPLIB);
1138 if (RT_FAILURE(rc))
1139 return RTMsgInitFailure(rc);
1140
1141 return TrustedMain(argc, argv, envp);
1142}
1143
1144# if defined(RT_OS_WINDOWS)
1145
1146static LRESULT CALLBACK WindowProc(HWND hwnd,
1147 UINT uMsg,
1148 WPARAM wParam,
1149 LPARAM lParam
1150)
1151{
1152 if(uMsg == WM_DESTROY)
1153 {
1154 PostQuitMessage(0);
1155 return 0;
1156 }
1157 return DefWindowProc (hwnd, uMsg, wParam, lParam);
1158}
1159
1160static LPCWSTR g_WndClassName = L"VBoxNetNatLwipClass";
1161
1162static DWORD WINAPI MsgThreadProc(__in LPVOID lpParameter)
1163{
1164 HWND hwnd = 0;
1165 HINSTANCE hInstance = (HINSTANCE)GetModuleHandle (NULL);
1166 bool bExit = false;
1167
1168 /* Register the Window Class. */
1169 WNDCLASS wc;
1170 wc.style = 0;
1171 wc.lpfnWndProc = WindowProc;
1172 wc.cbClsExtra = 0;
1173 wc.cbWndExtra = sizeof(void *);
1174 wc.hInstance = hInstance;
1175 wc.hIcon = NULL;
1176 wc.hCursor = NULL;
1177 wc.hbrBackground = (HBRUSH)(COLOR_BACKGROUND + 1);
1178 wc.lpszMenuName = NULL;
1179 wc.lpszClassName = g_WndClassName;
1180
1181 ATOM atomWindowClass = RegisterClass(&wc);
1182
1183 if (atomWindowClass != 0)
1184 {
1185 /* Create the window. */
1186 hwnd = CreateWindowEx (WS_EX_TOOLWINDOW | WS_EX_TRANSPARENT | WS_EX_TOPMOST,
1187 g_WndClassName, g_WndClassName,
1188 WS_POPUPWINDOW,
1189 -200, -200, 100, 100, NULL, NULL, hInstance, NULL);
1190
1191 if (hwnd)
1192 {
1193 SetWindowPos(hwnd, HWND_TOPMOST, -200, -200, 0, 0,
1194 SWP_NOACTIVATE | SWP_HIDEWINDOW | SWP_NOCOPYBITS | SWP_NOREDRAW | SWP_NOSIZE);
1195
1196 MSG msg;
1197 while (GetMessage(&msg, NULL, 0, 0))
1198 {
1199 TranslateMessage(&msg);
1200 DispatchMessage(&msg);
1201 }
1202
1203 DestroyWindow (hwnd);
1204
1205 bExit = true;
1206 }
1207
1208 UnregisterClass (g_WndClassName, hInstance);
1209 }
1210
1211 if(bExit)
1212 {
1213 /* no need any accuracy here, in anyway the DHCP server usually gets terminated with TerminateProcess */
1214 exit(0);
1215 }
1216
1217 return 0;
1218}
1219
1220
1221
1222/** (We don't want a console usually.) */
1223int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
1224{
1225#if 0
1226 NOREF(hInstance); NOREF(hPrevInstance); NOREF(lpCmdLine); NOREF(nCmdShow);
1227
1228 HANDLE hThread = CreateThread(
1229 NULL, /*__in_opt LPSECURITY_ATTRIBUTES lpThreadAttributes, */
1230 0, /*__in SIZE_T dwStackSize, */
1231 MsgThreadProc, /*__in LPTHREAD_START_ROUTINE lpStartAddress,*/
1232 NULL, /*__in_opt LPVOID lpParameter,*/
1233 0, /*__in DWORD dwCreationFlags,*/
1234 NULL /*__out_opt LPDWORD lpThreadId*/
1235 );
1236
1237 if(hThread != NULL)
1238 CloseHandle(hThread);
1239
1240#endif
1241 return main(__argc, __argv, environ);
1242}
1243# endif /* RT_OS_WINDOWS */
1244
1245#endif /* !VBOX_WITH_HARDENING */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette