VirtualBox

source: vbox/trunk/src/VBox/HostDrivers/VBoxNetFlt/solaris/VBoxNetFltBow-solaris.c@ 41702

Last change on this file since 41702 was 41702, checked in by vboxsync, 12 years ago

solaris/VBoxNetFltBow: header update.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 55.1 KB
Line 
1/* $Id: VBoxNetFltBow-solaris.c 41702 2012-06-14 10:15:11Z vboxsync $ */
2/** @file
3 * VBoxNetFlt - Network Filter Driver (Host), Solaris Specific Code.
4 */
5
6/*
7 * Copyright (C) 2008-2012 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 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27/*******************************************************************************
28* Header Files *
29*******************************************************************************/
30#define LOG_GROUP LOG_GROUP_NET_FLT_DRV
31#ifdef DEBUG_ramshankar
32# define LOG_ENABLED
33# define LOG_INSTANCE RTLogRelDefaultInstance()
34#endif
35#include <VBox/log.h>
36#include <VBox/err.h>
37#include <VBox/intnetinline.h>
38#include <VBox/version.h>
39#include <iprt/initterm.h>
40#include <iprt/alloca.h>
41#include <iprt/assert.h>
42#include <iprt/err.h>
43#include <iprt/string.h>
44#include <iprt/rand.h>
45#include <iprt/net.h>
46#include <iprt/spinlock.h>
47#include <iprt/mem.h>
48
49#include <sys/types.h>
50#include <sys/modctl.h>
51#include <sys/conf.h>
52#include <sys/stat.h>
53#include <sys/ddi.h>
54#include <sys/gld.h>
55#include <sys/sunddi.h>
56#include <sys/strsubr.h>
57#include <sys/dlpi.h>
58#include <sys/dls_mgmt.h>
59#include <sys/mac.h>
60#include <sys/strsun.h>
61
62#include <sys/vnic_mgmt.h>
63#include <sys/mac_client.h>
64#include <sys/mac_provider.h>
65#include <sys/dls.h>
66#include <sys/dld.h>
67#include <sys/cred.h>
68
69
70#define VBOXNETFLT_OS_SPECFIC 1
71#include "../VBoxNetFltInternal.h"
72
73/*******************************************************************************
74* Defined Constants And Macros *
75*******************************************************************************/
76/** The module name. */
77#define DEVICE_NAME "vboxbow"
78/** The module descriptions as seen in 'modinfo'. */
79#define DEVICE_DESC_DRV "VirtualBox NetBow"
80/** The dynamically created VNIC name (hardcoded in NetIf-solaris.cpp).
81 * @todo move this define into a common header. */
82#define VBOXBOW_VNIC_NAME "vboxvnic"
83/** The VirtualBox VNIC template name (hardcoded in NetIf-solaris.cpp).
84 * * @todo move this define into a common header. */
85#define VBOXBOW_VNIC_TEMPLATE_NAME "vboxvnic_template"
86/** Debugging switch for using symbols in kmdb */
87# define LOCAL static
88/** VBOXNETFLTVNIC::u32Magic */
89# define VBOXNETFLTVNIC_MAGIC 0x0ddfaced
90
91/** VLAN tag masking, should probably be in IPRT? */
92#define VLAN_ID(vlan) (((vlan) >> 0) & 0x0fffu)
93#define VLAN_CFI(vlan) (((vlan) >> 12) & 0x0001u)
94#define VLAN_PRI(vlan) (((vlan) >> 13) & 0x0007u)
95#define VLAN_TAG(pri,cfi,vid) (((pri) << 13) | ((cfi) << 12) | ((vid) << 0))
96
97typedef struct VLANHEADER
98{
99 uint16_t Type;
100 uint16_t Data;
101} VLANHEADER;
102typedef struct VLANHEADER *PVLANHEADER;
103
104/* Private: from sys/vlan.h */
105#ifndef VLAN_ID_NONE
106# define VLAN_ID_NONE 0
107#endif
108
109/* Private: from sys/param.h */
110#ifndef MAXLINKNAMESPECIFIER
111# define MAXLINKNAMESPECIFIER 96 /* MAXLINKNAMELEN + ZONENAME_MAX */
112#endif
113
114/* Private: from sys/mac_client_priv.h, mac client function prototypes. */
115extern uint16_t mac_client_vid(mac_client_handle_t hClient);
116extern void mac_client_get_resources(mac_client_handle_t hClient, mac_resource_props_t *pResources);
117extern int mac_client_set_resources(mac_client_handle_t hClient, mac_resource_props_t *pResources);
118
119
120/*******************************************************************************
121* Kernel Entry Hooks *
122*******************************************************************************/
123LOCAL int VBoxNetFltSolarisAttach(dev_info_t *pDip, ddi_attach_cmd_t enmCmd);
124LOCAL int VBoxNetFltSolarisDetach(dev_info_t *pDip, ddi_detach_cmd_t enmCmd);
125LOCAL int VBoxNetFltSolarisGetInfo(dev_info_t *pDip, ddi_info_cmd_t enmCmd, void *pArg, void **ppResult);
126
127
128/*******************************************************************************
129* Structures and Typedefs *
130*******************************************************************************/
131/**
132 * cb_ops: for drivers that support char/block entry points
133 */
134static struct cb_ops g_VBoxNetFltSolarisCbOps =
135{
136 nulldev, /* c open */
137 nulldev, /* c close */
138 nodev, /* b strategy */
139 nodev, /* b dump */
140 nodev, /* b print */
141 nodev, /* c read */
142 nodev, /* c write*/
143 nodev, /* c ioctl*/
144 nodev, /* c devmap */
145 nodev, /* c mmap */
146 nodev, /* c segmap */
147 nochpoll, /* c poll */
148 ddi_prop_op, /* property ops */
149 NULL, /* streamtab */
150 D_NEW | D_MP, /* compat. flag */
151 CB_REV, /* revision */
152 nodev, /* c aread */
153 nodev /* c awrite */
154};
155
156/**
157 * dev_ops: for driver device operations
158 */
159static struct dev_ops g_VBoxNetFltSolarisDevOps =
160{
161 DEVO_REV, /* driver build revision */
162 0, /* ref count */
163 VBoxNetFltSolarisGetInfo,
164 nulldev, /* identify */
165 nulldev, /* probe */
166 VBoxNetFltSolarisAttach,
167 VBoxNetFltSolarisDetach,
168 nodev, /* reset */
169 &g_VBoxNetFltSolarisCbOps,
170 NULL, /* bus ops */
171 nodev, /* power */
172 ddi_quiesce_not_needed
173};
174
175/**
176 * modldrv: export driver specifics to the kernel
177 */
178static struct modldrv g_VBoxNetFltSolarisModule =
179{
180 &mod_driverops, /* extern from kernel */
181 DEVICE_DESC_DRV " " VBOX_VERSION_STRING "r" RT_XSTR(VBOX_SVN_REV),
182 &g_VBoxNetFltSolarisDevOps
183};
184
185/**
186 * modlinkage: export install/remove/info to the kernel
187 */
188static struct modlinkage g_VBoxNetFltSolarisModLinkage =
189{
190 MODREV_1,
191 {
192 &g_VBoxNetFltSolarisModule,
193 NULL,
194 }
195};
196
197/*
198 * VBOXNETFLTVNICTEMPLATE: VNIC template information.
199 */
200typedef struct VBOXNETFLTVNICTEMPLATE
201{
202 /** The name of link on which the VNIC template is created on. */
203 char szLinkName[MAXNAMELEN];
204 /** The VLAN Id (can be VLAN_ID_NONE). */
205 uint16_t uVLANId;
206 /** Resources (bandwidth, CPU bindings, flow priority etc.) */
207 mac_resource_props_t Resources;
208} VBOXNETFLTVNICTEMPLATE;
209typedef struct VBOXNETFLTVNICTEMPLATE *PVBOXNETFLTVNICTEMPLATE;
210
211/**
212 * VBOXNETFLTVNIC: Per-VNIC instance data.
213 */
214typedef struct VBOXNETFLTVNIC
215{
216 /** Magic number (VBOXNETFLTVNIC_MAGIC). */
217 uint32_t u32Magic;
218 /** Whether we created the VNIC or not. */
219 bool fCreated;
220 /** Pointer to the VNIC template if any. */
221 PVBOXNETFLTVNICTEMPLATE pVNICTemplate;
222 /** Pointer to the VirtualBox interface instance. */
223 void *pvIf;
224 /** The MAC handle. */
225 mac_handle_t hInterface;
226 /** The VNIC link ID. */
227 datalink_id_t hLinkId;
228 /** The MAC client handle */
229 mac_client_handle_t hClient;
230 /** The unicast address handle. */
231 mac_unicast_handle_t hUnicast;
232 /** The promiscuous handle. */
233 mac_promisc_handle_t hPromisc;
234 /* The VNIC name. */
235 char szName[MAXLINKNAMESPECIFIER];
236 /** Handle to the next VNIC in the list. */
237 list_node_t hNode;
238} VBOXNETFLTVNIC;
239typedef struct VBOXNETFLTVNIC *PVBOXNETFLTVNIC;
240
241
242/*******************************************************************************
243* Global Variables *
244*******************************************************************************/
245/** Global Device handle we only support one instance. */
246static dev_info_t *g_pVBoxNetFltSolarisDip = NULL;
247/** Global Mutex (actually an rw lock). */
248static RTSEMFASTMUTEX g_VBoxNetFltSolarisMtx = NIL_RTSEMFASTMUTEX;
249/** The (common) global data. */
250static VBOXNETFLTGLOBALS g_VBoxNetFltSolarisGlobals;
251/** Global next-free VNIC Id (never decrements). */
252static volatile uint64_t g_VBoxNetFltSolarisVNICId = 0;
253
254
255/*******************************************************************************
256* Internal Functions *
257*******************************************************************************/
258LOCAL mblk_t *vboxNetFltSolarisMBlkFromSG(PVBOXNETFLTINS pThis, PINTNETSG pSG, uint32_t fDst);
259LOCAL unsigned vboxNetFltSolarisMBlkCalcSGSegs(PVBOXNETFLTINS pThis, mblk_t *pMsg);
260LOCAL int vboxNetFltSolarisMBlkToSG(PVBOXNETFLTINS pThis, mblk_t *pMsg, PINTNETSG pSG, unsigned cSegs, uint32_t fSrc);
261LOCAL void vboxNetFltSolarisRecv(void *pvData, mac_resource_handle_t hResource, mblk_t *pMsg, boolean_t fLoopback);
262LOCAL void vboxNetFltSolarisAnalyzeMBlk(mblk_t *pMsg);
263LOCAL int vboxNetFltSolarisReportInfo(PVBOXNETFLTINS pThis, mac_handle_t hInterface, bool fIsVNIC);
264LOCAL int vboxNetFltSolarisInitVNIC(PVBOXNETFLTINS pThis, PVBOXNETFLTVNIC pVNIC);
265LOCAL int vboxNetFltSolarisInitVNICTemplate(PVBOXNETFLTINS pThis, PVBOXNETFLTVNICTEMPLATE pVNICTemplate);
266LOCAL PVBOXNETFLTVNIC vboxNetFltSolarisAllocVNIC(void);
267LOCAL void vboxNetFltSolarisFreeVNIC(PVBOXNETFLTVNIC pVNIC);
268LOCAL void vboxNetFltSolarisDestroyVNIC(PVBOXNETFLTVNIC pVNIC);
269LOCAL int vboxNetFltSolarisCreateVNIC(PVBOXNETFLTINS pThis, PVBOXNETFLTVNIC *ppVNIC);
270LOCAL inline int vboxNetFltSolarisGetLinkId(const char *pszMacName, datalink_id_t *pLinkId);
271
272/**
273 * Kernel entry points
274 */
275int _init(void)
276{
277 Log((DEVICE_NAME ":_init\n"));
278
279 /*
280 * Prevent module autounloading.
281 */
282 modctl_t *pModCtl = mod_getctl(&g_VBoxNetFltSolarisModLinkage);
283 if (pModCtl)
284 pModCtl->mod_loadflags |= MOD_NOAUTOUNLOAD;
285 else
286 LogRel((DEVICE_NAME ":failed to disable autounloading!\n"));
287
288 /*
289 * Initialize IPRT.
290 */
291 int rc = RTR0Init(0);
292 if (RT_SUCCESS(rc))
293 {
294 /*
295 * Initialize Solaris specific globals here.
296 */
297 rc = RTSemFastMutexCreate(&g_VBoxNetFltSolarisMtx);
298 if (RT_SUCCESS(rc))
299 {
300 /*
301 * Initialize the globals and connect to the support driver.
302 *
303 * This will call back vboxNetFltOsOpenSupDrv (and maybe vboxNetFltOsCloseSupDrv)
304 * for establishing the connect to the support driver.
305 */
306 memset(&g_VBoxNetFltSolarisGlobals, 0, sizeof(g_VBoxNetFltSolarisGlobals));
307 rc = vboxNetFltInitGlobalsAndIdc(&g_VBoxNetFltSolarisGlobals);
308 if (RT_SUCCESS(rc))
309 {
310 rc = mod_install(&g_VBoxNetFltSolarisModLinkage);
311 if (!rc)
312 return rc;
313
314 LogRel((DEVICE_NAME ":mod_install failed. rc=%d\n", rc));
315 vboxNetFltTryDeleteIdcAndGlobals(&g_VBoxNetFltSolarisGlobals);
316 }
317 else
318 LogRel((DEVICE_NAME ":failed to initialize globals.\n"));
319
320 RTSemFastMutexDestroy(g_VBoxNetFltSolarisMtx);
321 g_VBoxNetFltSolarisMtx = NIL_RTSEMFASTMUTEX;
322 }
323
324 RTR0Term();
325 }
326 else
327 LogRel((DEVICE_NAME ":failed to initialize IPRT (rc=%d)\n", rc));
328
329 memset(&g_VBoxNetFltSolarisGlobals, 0, sizeof(g_VBoxNetFltSolarisGlobals));
330 return RTErrConvertToErrno(rc);
331}
332
333
334int _fini(void)
335{
336 int rc;
337 Log((DEVICE_NAME ":_fini\n"));
338
339 /*
340 * Undo the work done during start (in reverse order).
341 */
342 rc = vboxNetFltTryDeleteIdcAndGlobals(&g_VBoxNetFltSolarisGlobals);
343 if (RT_FAILURE(rc))
344 {
345 LogRel((DEVICE_NAME ":_fini - busy!\n"));
346 return EBUSY;
347 }
348
349 rc = mod_remove(&g_VBoxNetFltSolarisModLinkage);
350 if (!rc)
351 {
352 if (g_VBoxNetFltSolarisMtx != NIL_RTSEMFASTMUTEX)
353 {
354 RTSemFastMutexDestroy(g_VBoxNetFltSolarisMtx);
355 g_VBoxNetFltSolarisMtx = NIL_RTSEMFASTMUTEX;
356 }
357
358 RTR0Term();
359 }
360
361 return rc;
362}
363
364
365int _info(struct modinfo *pModInfo)
366{
367 Log((DEVICE_NAME ":_info\n"));
368
369 int rc = mod_info(&g_VBoxNetFltSolarisModLinkage, pModInfo);
370
371 Log((DEVICE_NAME ":_info returns %d\n", rc));
372 return rc;
373}
374
375
376/**
377 * Attach entry point, to attach a device to the system or resume it.
378 *
379 * @param pDip The module structure instance.
380 * @param enmCmd Operation type (attach/resume).
381 *
382 * @returns corresponding solaris error code.
383 */
384LOCAL int VBoxNetFltSolarisAttach(dev_info_t *pDip, ddi_attach_cmd_t enmCmd)
385{
386 Log((DEVICE_NAME ":VBoxNetFltSolarisAttach pDip=%p enmCmd=%d\n", pDip, enmCmd));
387
388 switch (enmCmd)
389 {
390 case DDI_ATTACH:
391 {
392 g_pVBoxNetFltSolarisDip = pDip;
393 return DDI_SUCCESS;
394 }
395
396 case DDI_RESUME:
397 {
398 /* Nothing to do here... */
399 return DDI_SUCCESS;
400 }
401
402 /* case DDI_PM_RESUME: */
403 default:
404 return DDI_FAILURE;
405 }
406}
407
408
409/**
410 * Detach entry point, to detach a device to the system or suspend it.
411 *
412 * @param pDip The module structure instance.
413 * @param enmCmd Operation type (detach/suspend).
414 *
415 * @returns corresponding solaris error code.
416 */
417LOCAL int VBoxNetFltSolarisDetach(dev_info_t *pDip, ddi_detach_cmd_t enmCmd)
418{
419 Log((DEVICE_NAME ":VBoxNetFltSolarisDetach pDip=%p enmCmd=%d\n", pDip, enmCmd));
420
421 switch (enmCmd)
422 {
423 case DDI_DETACH:
424 {
425 return DDI_SUCCESS;
426 }
427
428 case DDI_RESUME:
429 {
430 /* Nothing to do here... */
431 return DDI_SUCCESS;
432 }
433
434 /* case DDI_PM_SUSPEND: */
435 /* case DDI_HOT_PLUG_DETACH: */
436 default:
437 return DDI_FAILURE;
438 }
439}
440
441
442/**
443 * Info entry point, called by solaris kernel for obtaining driver info.
444 *
445 * @param pDip The module structure instance (do not use).
446 * @param enmCmd Information request type.
447 * @param pvArg Type specific argument.
448 * @param ppvResult Where to store the requested info.
449 *
450 * @returns corresponding solaris error code.
451 */
452LOCAL int VBoxNetFltSolarisGetInfo(dev_info_t *pDip, ddi_info_cmd_t enmCmd, void *pvArg, void **ppResult)
453{
454 Log((DEVICE_NAME ":VBoxNetFltSolarisGetInfo pDip=%p enmCmd=%d pArg=%p instance=%d\n", pDip, enmCmd, getminor((dev_t)pvArg)));
455
456 switch (enmCmd)
457 {
458 case DDI_INFO_DEVT2DEVINFO:
459 {
460 *ppResult = g_pVBoxNetFltSolarisDip;
461 return DDI_SUCCESS;
462 }
463
464 case DDI_INFO_DEVT2INSTANCE:
465 {
466 int instance = getminor((dev_t)pvArg);
467 *ppResult = (void *)(uintptr_t)instance;
468 return DDI_SUCCESS;
469 }
470 }
471
472 return DDI_FAILURE;
473}
474
475
476/**
477 * Create a solaris message block from the SG list.
478 *
479 * @param pThis The instance.
480 * @param pSG Pointer to the scatter-gather list.
481 *
482 * @returns Solaris message block.
483 */
484LOCAL inline mblk_t *vboxNetFltSolarisMBlkFromSG(PVBOXNETFLTINS pThis, PINTNETSG pSG, uint32_t fDst)
485{
486 Log((DEVICE_NAME ":vboxNetFltSolarisMBlkFromSG pThis=%p pSG=%p\n", pThis, pSG));
487
488 mblk_t *pMsg = allocb(pSG->cbTotal, BPRI_HI);
489 if (RT_UNLIKELY(!pMsg))
490 {
491 LogRel((DEVICE_NAME ":vboxNetFltSolarisMBlkFromSG failed to alloc %d bytes for mblk_t.\n", pSG->cbTotal));
492 return NULL;
493 }
494
495 /*
496 * Single buffer copy. Maybe later explore the
497 * need/possibility for using a mblk_t chain rather.
498 */
499 for (unsigned i = 0; i < pSG->cSegsUsed; i++)
500 {
501 if (pSG->aSegs[i].pv)
502 {
503 bcopy(pSG->aSegs[i].pv, pMsg->b_wptr, pSG->aSegs[i].cb);
504 pMsg->b_wptr += pSG->aSegs[i].cb;
505 }
506 }
507 return pMsg;
508}
509
510
511/**
512 * Calculate the number of segments required for this message block.
513 *
514 * @param pThis The instance
515 * @param pMsg Pointer to the data message.
516 *
517 * @returns Number of segments.
518 */
519LOCAL unsigned vboxNetFltSolarisMBlkCalcSGSegs(PVBOXNETFLTINS pThis, mblk_t *pMsg)
520{
521 unsigned cSegs = 0;
522 for (mblk_t *pCur = pMsg; pCur; pCur = pCur->b_cont)
523 if (MBLKL(pCur))
524 cSegs++;
525
526#ifdef PADD_RUNT_FRAMES_FROM_HOST
527 if (msgdsize(pMsg) < 60)
528 cSegs++;
529#endif
530
531 NOREF(pThis);
532 return RT_MAX(cSegs, 1);
533}
534
535
536/**
537 * Initializes an SG list from the given message block.
538 *
539 * @param pThis The instance.
540 * @param pMsg Pointer to the data message.
541 The caller must ensure it's not a control message block.
542 * @param pSG Pointer to the SG.
543 * @param cSegs Number of segments in the SG.
544 * This should match the number in the message block exactly!
545 * @param fSrc The source of the message.
546 *
547 * @returns VBox status code.
548 */
549LOCAL int vboxNetFltSolarisMBlkToSG(PVBOXNETFLTINS pThis, mblk_t *pMsg, PINTNETSG pSG, unsigned cSegs, uint32_t fSrc)
550{
551 Log((DEVICE_NAME ":vboxNetFltSolarisMBlkToSG pThis=%p pMsg=%p pSG=%p cSegs=%d\n", pThis, pMsg, pSG, cSegs));
552
553 /*
554 * Convert the message block to segments. Works cbTotal and sets cSegsUsed.
555 */
556 IntNetSgInitTempSegs(pSG, 0 /*cbTotal*/, cSegs, 0 /*cSegsUsed*/);
557 mblk_t *pCur = pMsg;
558 unsigned iSeg = 0;
559 while (pCur)
560 {
561 size_t cbSeg = MBLKL(pCur);
562 if (cbSeg)
563 {
564 void *pvSeg = pCur->b_rptr;
565 pSG->aSegs[iSeg].pv = pvSeg;
566 pSG->aSegs[iSeg].cb = cbSeg;
567 pSG->aSegs[iSeg].Phys = NIL_RTHCPHYS;
568 pSG->cbTotal += cbSeg;
569 iSeg++;
570 }
571 pCur = pCur->b_cont;
572 }
573 pSG->cSegsUsed = iSeg;
574
575#ifdef PADD_RUNT_FRAMES_FROM_HOST
576 if (pSG->cbTotal < 60 && (fSrc & INTNETTRUNKDIR_HOST))
577 {
578 Log((DEVICE_NAME ":vboxNetFltSolarisMBlkToSG pulling up to length.\n"));
579
580 static uint8_t const s_abZero[128] = {0};
581 pSG->aSegs[iSeg].Phys = NIL_RTHCPHYS;
582 pSG->aSegs[iSeg].pv = (void *)&s_abZero[0];
583 pSG->aSegs[iSeg].cb = 60 - pSG->cbTotal;
584 pSG->cbTotal = 60;
585 pSG->cSegsUsed++;
586 Assert(iSeg + 1 < cSegs);
587 }
588#endif
589
590 Log((DEVICE_NAME ":vboxNetFltSolarisMBlkToSG iSeg=%d pSG->cbTotal=%d msgdsize=%d\n", iSeg, pSG->cbTotal, msgdsize(pMsg)));
591 return VINF_SUCCESS;
592}
593
594
595/**
596 * Simple packet dump, used for internal debugging.
597 *
598 * @param pMsg Pointer to the message to analyze and dump.
599 */
600LOCAL void vboxNetFltSolarisAnalyzeMBlk(mblk_t *pMsg)
601{
602 LogFunc((DEVICE_NAME ":vboxNetFltSolarisAnalyzeMBlk pMsg=%p\n", pMsg));
603
604 PCRTNETETHERHDR pEthHdr = (PCRTNETETHERHDR)pMsg->b_rptr;
605 uint8_t *pb = pMsg->b_rptr;
606 if (pEthHdr->EtherType == RT_H2BE_U16(RTNET_ETHERTYPE_IPV4))
607 {
608 PRTNETIPV4 pIpHdr = (PRTNETIPV4)(pEthHdr + 1);
609 if (!pMsg->b_cont)
610 {
611 if (pIpHdr->ip_p == RTNETIPV4_PROT_ICMP)
612 LogRel((DEVICE_NAME ":ICMP D=%.6Rhxs S=%.6Rhxs T=%04x\n", pb, pb + 6, RT_BE2H_U16(*(uint16_t *)(pb + 12))));
613 else if (pIpHdr->ip_p == RTNETIPV4_PROT_TCP)
614 LogRel((DEVICE_NAME ":TCP D=%.6Rhxs S=%.6Rhxs\n", pb, pb + 6));
615 else if (pIpHdr->ip_p == RTNETIPV4_PROT_UDP)
616 {
617 PCRTNETUDP pUdpHdr = (PCRTNETUDP)((uint32_t *)pIpHdr + pIpHdr->ip_hl);
618 if ( RT_BE2H_U16(pUdpHdr->uh_sport) == 67
619 && RT_BE2H_U16(pUdpHdr->uh_dport) == 68)
620 {
621 LogRel((DEVICE_NAME ":UDP bootp ack D=%.6Rhxs S=%.6Rhxs UDP_CheckSum=%04x Computex=%04x\n", pb, pb + 6,
622 RT_BE2H_U16(pUdpHdr->uh_sum), RT_BE2H_U16(RTNetIPv4UDPChecksum(pIpHdr, pUdpHdr, pUdpHdr + 1))));
623 }
624 }
625 }
626 else
627 {
628 Log((DEVICE_NAME ":Chained IP packet. Skipping validity check.\n"));
629 }
630 }
631 else if (pEthHdr->EtherType == RT_H2BE_U16(RTNET_ETHERTYPE_VLAN))
632 {
633 PVLANHEADER pVlanHdr = (PVLANHEADER)(pMsg->b_rptr + sizeof(RTNETETHERHDR) - sizeof(pEthHdr->EtherType));
634 LogRel((DEVICE_NAME ":VLAN Pcp=%u Cfi=%u Id=%u\n", VLAN_PRI(RT_BE2H_U16(pVlanHdr->Data)), VLAN_CFI(RT_BE2H_U16(pVlanHdr->Data)), VLAN_ID(RT_BE2H_U16(pVlanHdr->Data))));
635 LogRel((DEVICE_NAME "%.*Rhxd\n", sizeof(VLANHEADER), pVlanHdr));
636 }
637 else if (pEthHdr->EtherType == RT_H2BE_U16(RTNET_ETHERTYPE_ARP))
638 {
639 PRTNETARPHDR pArpHdr = (PRTNETARPHDR)(pEthHdr + 1);
640 LogRel((DEVICE_NAME ":ARP Op=%d\n", pArpHdr->ar_oper));
641 }
642 else if (pEthHdr->EtherType == RT_H2BE_U16(RTNET_ETHERTYPE_IPV6))
643 {
644 LogRel((DEVICE_NAME ":IPv6 D=%.6Rhxs S=%.6Rhxs\n", pb, pb + 6));
645 }
646 else if (pEthHdr->EtherType == RT_H2BE_U16(RTNET_ETHERTYPE_IPX_1)
647 || pEthHdr->EtherType == RT_H2BE_U16(RTNET_ETHERTYPE_IPX_2)
648 || pEthHdr->EtherType == RT_H2BE_U16(RTNET_ETHERTYPE_IPX_3))
649 {
650 LogRel((DEVICE_NAME ":IPX packet.\n"));
651 }
652 else
653 {
654 LogRel((DEVICE_NAME ":Unknown EtherType=%x D=%.6Rhxs S=%.6Rhxs\n", RT_H2BE_U16(pEthHdr->EtherType), &pEthHdr->DstMac,
655 &pEthHdr->SrcMac));
656 /* Log((DEVICE_NAME ":%.*Rhxd\n", MBLKL(pMsg), pMsg->b_rptr)); */
657 }
658}
659
660
661/**
662 * Helper.
663 */
664DECLINLINE(bool) vboxNetFltPortSolarisIsHostMac(PVBOXNETFLTINS pThis, PCRTMAC pMac)
665{
666 return pThis->u.s.MacAddr.au16[0] == pMac->au16[0]
667 && pThis->u.s.MacAddr.au16[1] == pMac->au16[1]
668 && pThis->u.s.MacAddr.au16[2] == pMac->au16[2];
669}
670
671
672/**
673 * Receive (rx) entry point.
674 *
675 * @param pvData Private data.
676 * @param hResource The resource handle.
677 * @param pMsg The packet.
678 * @param fLoopback Whether this is a loopback packet or not.
679 */
680LOCAL void vboxNetFltSolarisRecv(void *pvData, mac_resource_handle_t hResource, mblk_t *pMsg, boolean_t fLoopback)
681{
682 Log((DEVICE_NAME ":vboxNetFltSolarisRecv pvData=%p pMsg=%p fLoopback=%d cbData=%d\n", pvData, pMsg, fLoopback, pMsg ? MBLKL(pMsg) : 0));
683
684 PVBOXNETFLTINS pThis = (PVBOXNETFLTINS)pvData;
685 AssertPtrReturnVoid(pThis);
686 AssertPtrReturnVoid(pMsg);
687
688 /*
689 * Active? Retain the instance and increment the busy counter.
690 */
691 if (!vboxNetFltTryRetainBusyActive(pThis))
692 {
693 freemsgchain(pMsg);
694 return;
695 }
696
697 uint32_t fSrc = INTNETTRUNKDIR_WIRE;
698 PRTNETETHERHDR pEthHdr = (PRTNETETHERHDR)pMsg->b_rptr;
699 if ( MBLKL(pMsg) >= sizeof(RTNETETHERHDR)
700 && vboxNetFltPortSolarisIsHostMac(pThis, &pEthHdr->SrcMac))
701 fSrc = INTNETTRUNKDIR_HOST;
702
703 /*
704 * Route all received packets into the internal network.
705 */
706 uint16_t cFailed = 0;
707 for (mblk_t *pCurMsg = pMsg; pCurMsg != NULL; pCurMsg = pCurMsg->b_next)
708 {
709 unsigned cSegs = vboxNetFltSolarisMBlkCalcSGSegs(pThis, pCurMsg);
710 PINTNETSG pSG = (PINTNETSG)alloca(RT_OFFSETOF(INTNETSG, aSegs[cSegs]));
711 int rc = vboxNetFltSolarisMBlkToSG(pThis, pMsg, pSG, cSegs, fSrc);
712 if (RT_SUCCESS(rc))
713 pThis->pSwitchPort->pfnRecv(pThis->pSwitchPort, NULL, pSG, fSrc);
714 else
715 cFailed++;
716 }
717 vboxNetFltRelease(pThis, true /* fBusy */);
718
719 if (RT_UNLIKELY(cFailed))
720 LogRel((DEVICE_NAME ":vboxNetFltSolarisMBlkToSG failed for %u packets.\n", cFailed));
721
722 freemsgchain(pMsg);
723
724 NOREF(hResource);
725}
726
727
728#if 0
729/**
730 * MAC layer link notification hook.
731 *
732 * @param pvArg Opaque pointer to the instance.
733 * @param Type Notification Type.
734 *
735 * @remarks This hook will be invoked for various changes to the underlying
736 * interface even when VMs aren't running so don't do any funky stuff
737 * here.
738 */
739LOCAL void vboxNetFltSolarisLinkNotify(void *pvArg, mac_notify_type_t Type)
740{
741 LogRel((DEVICE_NAME ":vboxNetFltSolarisLinkNotify pvArg=%p Type=%d\n", pvArg, Type));
742
743 PVBOXNETFLTINS pThis = pvArg;
744 AssertReturnVoid(VALID_PTR(pThis));
745 AssertReturnVoid(pThis->u.s.hInterface);
746
747 switch (Type)
748 {
749 case MAC_NOTE_LINK:
750 {
751 LogRel((DEVICE_NAME ":vboxNetFltSolarisLinkNotify link state change\n"));
752 link_state_t hLinkState = mac_stat_get(pThis->u.s.hInterface, MAC_STAT_LINK_STATE);
753 bool fDisconnectedFromHost = hLinkState == LINK_STATE_UP ? false : true;
754 if (fDisconnectedFromHost != ASMAtomicUoReadBool(&pThis->fDisconnectedFromHost))
755 {
756 ASMAtomicUoWriteBool(&pThis->fDisconnectedFromHost, fDisconnectedFromHost);
757 LogRel((DEVICE_NAME ":vboxNetFltSolarisLinkNotify link state change: new state=%s\n", fDisconnectedFromHost ? "DOWN" : "UP"));
758 }
759 break;
760 }
761
762 default:
763 return;
764 }
765}
766#endif
767
768
769/**
770 * Report capabilities and MAC address to IntNet after obtaining the MAC address
771 * of the underlying interface for a VNIC or the current interface if it's a
772 * physical/ether-stub interface.
773 *
774 * @param pThis The instance.
775 * @param hInterface The Interface handle.
776 * @param fIsVNIC Whether this interface handle corresponds to a VNIC
777 * or not.
778 *
779 * @remarks Retains the instance while doing it's job.
780 * @returns VBox status code.
781 */
782LOCAL int vboxNetFltSolarisReportInfo(PVBOXNETFLTINS pThis, mac_handle_t hInterface, bool fIsVNIC)
783{
784 mac_handle_t hLowerMac = NULL;
785 if (!fIsVNIC)
786 hLowerMac = hInterface;
787 else
788 {
789 hLowerMac = mac_get_lower_mac_handle(hInterface);
790 if (RT_UNLIKELY(!hLowerMac))
791 {
792 LogRel((DEVICE_NAME ":vboxNetFltSolarisReportInfo failed to get lower MAC handle for '%s'\n", pThis->szName));
793 return VERR_INVALID_HANDLE;
794 }
795 }
796
797 pThis->u.s.hInterface = hLowerMac;
798
799#if 0
800 /*
801 * Try setup link notification hooks, this might fail if mac_no_notification()
802 * doesn't support it. We won't bother using the private function since link notification
803 * isn't critical for us and ignore failures.
804 */
805 pThis->u.s.hNotify = mac_notify_add(hLowerMac, vboxNetFltSolarisLinkNotify, pThis);
806 if (!pThis->u.s.hNotify)
807 LogRel((DEVICE_NAME ":vboxNetFltSolarisReportInfo Warning! Failed to setup link notification hook.\n"));
808#endif
809
810 mac_unicast_primary_get(hLowerMac, (uint8_t *)pThis->u.s.MacAddr.au8);
811 if (vboxNetFltTryRetainBusyNotDisconnected(pThis))
812 {
813 Assert(pThis->pSwitchPort);
814 Log((DEVICE_NAME ":vboxNetFltSolarisReportInfo phys mac %.6Rhxs\n", &pThis->u.s.MacAddr));
815 pThis->pSwitchPort->pfnReportMacAddress(pThis->pSwitchPort, &pThis->u.s.MacAddr);
816 pThis->pSwitchPort->pfnReportPromiscuousMode(pThis->pSwitchPort, false); /** @todo Promisc */
817 pThis->pSwitchPort->pfnReportGsoCapabilities(pThis->pSwitchPort, 0, INTNETTRUNKDIR_WIRE | INTNETTRUNKDIR_HOST);
818 pThis->pSwitchPort->pfnReportNoPreemptDsts(pThis->pSwitchPort, 0 /* none */);
819 vboxNetFltRelease(pThis, true /*fBusy*/);
820 return VINF_SUCCESS;
821 }
822 else
823 LogRel((DEVICE_NAME ":vboxNetFltSolarisReportInfo failed to retain interface. pThis=%p\n", pThis));
824
825 return VERR_INTNET_FLT_IF_BUSY;
826}
827
828
829/**
830 * Initialize a VNIC, optionally from a template.
831 *
832 * @param pThis The instance.
833 * @param pVNIC Pointer to the VNIC.
834 * @param pVNICTemplate Pointer to the VNIC template initialize from, can be
835 * NULL.
836 *
837 * @returns VBox status code.
838 */
839LOCAL int vboxNetFltSolarisInitVNIC(PVBOXNETFLTINS pThis, PVBOXNETFLTVNIC pVNIC)
840{
841 /*
842 * Some paranoia.
843 */
844 AssertReturn(pThis, VERR_INVALID_PARAMETER);
845 AssertReturn(pVNIC, VERR_INVALID_PARAMETER);
846 AssertReturn(pVNIC->hInterface, VERR_INVALID_POINTER);
847 AssertReturn(pVNIC->hLinkId != DATALINK_INVALID_LINKID, VERR_INVALID_HANDLE);
848 AssertReturn(!pVNIC->hClient, VERR_INVALID_POINTER);
849
850 int rc = mac_client_open(pVNIC->hInterface, &pVNIC->hClient,
851 NULL, /* name of this client */
852 MAC_OPEN_FLAGS_USE_DATALINK_NAME | /* client name same as underlying NIC */
853 MAC_OPEN_FLAGS_MULTI_PRIMARY /* allow multiple primary unicasts */
854 );
855 if (RT_LIKELY(!rc))
856 {
857 if (pVNIC->pVNICTemplate)
858 rc = mac_client_set_resources(pVNIC->hClient, &pVNIC->pVNICTemplate->Resources);
859
860 if (RT_LIKELY(!rc))
861 {
862 Log((DEVICE_NAME ":vboxNetFltSolarisInitVNIC succesfully initialized VNIC.\n"));
863 return VINF_SUCCESS;
864 }
865 else
866 {
867 LogRel((DEVICE_NAME ":vboxNetFltSolarisInitVNIC mac_client_set_resources failed. rc=%d\n", rc));
868 rc = VERR_INTNET_FLT_VNIC_CREATE_FAILED;
869 }
870
871 mac_client_close(pVNIC->hClient, 0 /* flags */);
872 pVNIC->hClient = NULL;
873 }
874 else
875 LogRel((DEVICE_NAME ":vboxNetFltSolarisInitVNIC failed to open mac client for '%s' rc=%d\n", pThis->szName, rc));
876
877 return rc;
878}
879
880
881/**
882 * Initializes the VNIC template. This involves opening the template VNIC to
883 * retreive info. like the VLAN Id, underlying MAC address etc.
884 *
885 * @param pThis The VM connection instance.
886 * @param pVNICTemplate Pointer to a VNIC template to initialize.
887 *
888 * @returns VBox status code.
889 */
890LOCAL int vboxNetFltSolarisInitVNICTemplate(PVBOXNETFLTINS pThis, PVBOXNETFLTVNICTEMPLATE pVNICTemplate)
891{
892 Log((DEVICE_NAME ":vboxNetFltSolarisInitVNICTemplate pThis=%p pVNICTemplate=%p\n", pThis, pVNICTemplate));
893
894 AssertReturn(pVNICTemplate, VERR_INVALID_PARAMETER);
895 AssertReturn(pThis->u.s.fIsVNICTemplate == true, VERR_INVALID_STATE);
896
897 /*
898 * Get the VNIC template's datalink ID.
899 */
900 datalink_id_t VNICLinkId;
901 int rc = vboxNetFltSolarisGetLinkId(pThis->szName, &VNICLinkId);
902 if (RT_SUCCESS(rc))
903 {
904 /*
905 * Open the VNIC to obtain a MAC handle so as to retreive the VLAN ID.
906 */
907 mac_handle_t hInterface;
908 rc = mac_open_by_linkid(VNICLinkId, &hInterface);
909 if (!rc)
910 {
911 /*
912 * Get the underlying linkname.
913 */
914 mac_handle_t hPhysLinkHandle = mac_get_lower_mac_handle(hInterface);
915 if (RT_LIKELY(hPhysLinkHandle))
916 {
917 const char *pszLinkName = mac_name(hPhysLinkHandle);
918 rc = RTStrCopy(pVNICTemplate->szLinkName, sizeof(pVNICTemplate->szLinkName), pszLinkName);
919 if (RT_SUCCESS(rc))
920 {
921 /*
922 * Now open the VNIC template to retrieve the VLAN Id & resources.
923 */
924 mac_client_handle_t hClient;
925 rc = mac_client_open(hInterface, &hClient,
926 NULL, /* name of this client */
927 MAC_OPEN_FLAGS_USE_DATALINK_NAME | /* client name same as underlying NIC */
928 MAC_OPEN_FLAGS_MULTI_PRIMARY /* allow multiple primary unicasts */
929 );
930 if (RT_LIKELY(!rc))
931 {
932 pVNICTemplate->uVLANId = mac_client_vid(hClient);
933 mac_client_get_resources(hClient, &pVNICTemplate->Resources);
934 mac_client_close(hClient, 0 /* fFlags */);
935 mac_close(hInterface);
936
937 Log((DEVICE_NAME ":vboxNetFltSolarisInitVNICTemplate successfully init. VNIC template. szLinkName=%s\n",
938 pVNICTemplate->szLinkName));
939 return VINF_SUCCESS;
940 }
941 else
942 {
943 LogRel((DEVICE_NAME ":vboxNetFltSolarisInitVNICTemplate failed to open VNIC template. rc=%d\n", rc));
944 rc = VERR_INTNET_FLT_IF_FAILED;
945 }
946 }
947 else
948 LogRel((DEVICE_NAME ":vboxNetFltSolarisInitVNICTemplate failed to copy link name of underlying interface. rc=%d\n", rc));
949 }
950 else
951 {
952 LogRel((DEVICE_NAME ":vboxNetFltSolarisInitVNICTemplate failed to get lower handle for VNIC template '%s'.\n", pThis->szName));
953 rc = VERR_INTNET_FLT_IF_FAILED;
954 }
955
956 mac_close(hInterface);
957 }
958 else
959 {
960 LogRel((DEVICE_NAME ":vboxNetFltSolarisInitVNICTemplate failed to open by link ID. rc=%d\n", rc));
961 rc = VERR_INTNET_FLT_IF_FAILED;
962 }
963 }
964 else
965 LogRel((DEVICE_NAME ":vboxNetFltSolarisInitVNICTemplate failed to get VNIC template link Id. rc=%d\n", rc));
966
967 return rc;
968}
969
970
971/**
972 * Allocate a VNIC structure.
973 *
974 * @returns An allocated VNIC structure or NULL in case of errors.
975 */
976LOCAL PVBOXNETFLTVNIC vboxNetFltSolarisAllocVNIC(void)
977{
978 PVBOXNETFLTVNIC pVNIC = RTMemAllocZ(sizeof(VBOXNETFLTVNIC));
979 if (RT_UNLIKELY(!pVNIC))
980 return NULL;
981
982 pVNIC->u32Magic = VBOXNETFLTVNIC_MAGIC;
983 pVNIC->fCreated = false;
984 pVNIC->pVNICTemplate = NULL;
985 pVNIC->pvIf = NULL;
986 pVNIC->hInterface = NULL;
987 pVNIC->hLinkId = DATALINK_INVALID_LINKID;
988 pVNIC->hClient = NULL;
989 pVNIC->hUnicast = NULL;
990 pVNIC->hPromisc = NULL;
991 RT_ZERO(pVNIC->szName);
992 list_link_init(&pVNIC->hNode);
993 return pVNIC;
994}
995
996
997/**
998 * Frees an allocated VNIC.
999 *
1000 * @param pVNIC Pointer to the VNIC.
1001 */
1002LOCAL inline void vboxNetFltSolarisFreeVNIC(PVBOXNETFLTVNIC pVNIC)
1003{
1004 RTMemFree(pVNIC);
1005}
1006
1007
1008/**
1009 * Destroy a created VNIC if it was created by us, or just
1010 * de-initializes the VNIC freeing up resources handles.
1011 *
1012 * @param pVNIC Pointer to the VNIC.
1013 */
1014LOCAL void vboxNetFltSolarisDestroyVNIC(PVBOXNETFLTVNIC pVNIC)
1015{
1016 AssertPtrReturnVoid(pVNIC);
1017 AssertMsgReturnVoid(pVNIC->u32Magic == VBOXNETFLTVNIC_MAGIC, ("pVNIC=%p u32Magic=%#x\n", pVNIC, pVNIC->u32Magic));
1018 if (pVNIC)
1019 {
1020 if (pVNIC->hClient)
1021 {
1022#if 0
1023 if (pVNIC->hUnicast)
1024 {
1025 mac_unicast_remove(pVNIC->hClient, pVNIC->hUnicast);
1026 pVNIC->hUnicast = NULL;
1027 }
1028#endif
1029
1030 if (pVNIC->hPromisc)
1031 {
1032 mac_promisc_remove(pVNIC->hPromisc);
1033 pVNIC->hPromisc = NULL;
1034 }
1035
1036 mac_rx_clear(pVNIC->hClient);
1037
1038 mac_client_close(pVNIC->hClient, 0 /* fFlags */);
1039 pVNIC->hClient = NULL;
1040 }
1041
1042 if (pVNIC->hInterface)
1043 {
1044 mac_close(pVNIC->hInterface);
1045 pVNIC->hInterface = NULL;
1046 }
1047
1048 if (pVNIC->fCreated)
1049 {
1050 vnic_delete(pVNIC->hLinkId, 0 /* Flags */);
1051 pVNIC->hLinkId = DATALINK_INVALID_LINKID;
1052 pVNIC->fCreated = false;
1053 }
1054
1055 if (pVNIC->pVNICTemplate)
1056 {
1057 RTMemFree(pVNIC->pVNICTemplate);
1058 pVNIC->pVNICTemplate = NULL;
1059 }
1060 }
1061}
1062
1063
1064/**
1065 * Create a non-persistent VNIC over the given interface.
1066 *
1067 * @param pThis The VM connection instance.
1068 * @param ppVNIC Where to store the created VNIC.
1069 *
1070 * @returns VBox status code.
1071 */
1072LOCAL int vboxNetFltSolarisCreateVNIC(PVBOXNETFLTINS pThis, PVBOXNETFLTVNIC *ppVNIC)
1073{
1074 Log((DEVICE_NAME ":vboxNetFltSolarisCreateVNIC pThis=%p\n", pThis));
1075
1076 AssertReturn(pThis, VERR_INVALID_POINTER);
1077 AssertReturn(ppVNIC, VERR_INVALID_POINTER);
1078
1079 int rc = VERR_INVALID_STATE;
1080 PVBOXNETFLTVNIC pVNIC = vboxNetFltSolarisAllocVNIC();
1081 if (RT_UNLIKELY(!pVNIC))
1082 return VERR_NO_MEMORY;
1083
1084 /*
1085 * Set a random MAC address for now. It will be changed to the VM interface's
1086 * MAC address later, see vboxNetFltPortOsNotifyMacAddress().
1087 */
1088 RTMAC GuestMac;
1089 GuestMac.au8[0] = 0x08;
1090 GuestMac.au8[1] = 0x00;
1091 GuestMac.au8[2] = 0x27;
1092 RTRandBytes(&GuestMac.au8[3], 3);
1093
1094 AssertCompile(sizeof(RTMAC) <= MAXMACADDRLEN);
1095
1096 const char *pszLinkName = pThis->szName;
1097 uint16_t uVLANId = VLAN_ID_NONE;
1098 vnic_mac_addr_type_t AddrType = VNIC_MAC_ADDR_TYPE_FIXED;
1099 vnic_ioc_diag_t Diag = VNIC_IOC_DIAG_NONE;
1100 int MacSlot = 0;
1101 int MacLen = sizeof(GuestMac);
1102 uint32_t fFlags = 0;
1103
1104 if (pThis->u.s.fIsVNICTemplate)
1105 {
1106 pVNIC->pVNICTemplate = RTMemAllocZ(sizeof(VBOXNETFLTVNICTEMPLATE));
1107 if (RT_UNLIKELY(!pVNIC->pVNICTemplate))
1108 {
1109 vboxNetFltSolarisFreeVNIC(pVNIC);
1110 return VERR_NO_MEMORY;
1111 }
1112
1113 /*
1114 * Initialize the VNIC template.
1115 */
1116 rc = vboxNetFltSolarisInitVNICTemplate(pThis, pVNIC->pVNICTemplate);
1117 if (RT_FAILURE(rc))
1118 {
1119 LogRel((DEVICE_NAME ":vboxNetFltSolarisCreateVNIC failed to initialize VNIC from VNIC template. rc=%Rrc\n", rc));
1120 vboxNetFltSolarisFreeVNIC(pVNIC);
1121 return rc;
1122 }
1123
1124 pszLinkName = pVNIC->pVNICTemplate->szLinkName;
1125 uVLANId = pVNIC->pVNICTemplate->uVLANId;
1126#if 0
1127 /*
1128 * Required only if we're creating a VLAN interface & not a VNIC with a VLAN Id.
1129 */
1130 if (uVLANId != VLAN_ID_NONE)
1131 fFlags |= MAC_VLAN;
1132#endif
1133 Log((DEVICE_NAME ":vboxNetFltSolarisCreateVNIC pThis=%p VLAN Id=%u\n", pThis, uVLANId));
1134 }
1135
1136 /*
1137 * Create the VNIC under 'pszLinkName', which can be the one from the VNIC template or can
1138 * be a physical interface.
1139 */
1140 rc = RTSemFastMutexRequest(g_VBoxNetFltSolarisMtx); AssertRC(rc);
1141 RTStrPrintf(pVNIC->szName, sizeof(pVNIC->szName), "%s%RU64", VBOXBOW_VNIC_NAME, g_VBoxNetFltSolarisVNICId);
1142 rc = vnic_create(pVNIC->szName, pszLinkName, &AddrType, &MacLen, GuestMac.au8, &MacSlot, 0 /* Mac-Prefix Length */, uVLANId,
1143 fFlags, &pVNIC->hLinkId, &Diag, NULL /* Reserved */);
1144 if (!rc)
1145 {
1146 pVNIC->fCreated = true;
1147 ASMAtomicIncU64(&g_VBoxNetFltSolarisVNICId);
1148 RTSemFastMutexRelease(g_VBoxNetFltSolarisMtx);
1149
1150 /*
1151 * Now try opening the created VNIC.
1152 */
1153 rc = mac_open_by_linkid(pVNIC->hLinkId, &pVNIC->hInterface);
1154 if (!rc)
1155 {
1156 /*
1157 * Initialize the VNIC from the physical interface or the VNIC template.
1158 */
1159 rc = vboxNetFltSolarisInitVNIC(pThis, pVNIC);
1160 if (RT_SUCCESS(rc))
1161 {
1162 Log((DEVICE_NAME ":vboxNetFltSolarisCreateVNIC successfully created VNIC '%s' over '%s' with random mac %.6Rhxs\n",
1163 pVNIC->szName, pszLinkName, &GuestMac));
1164 *ppVNIC = pVNIC;
1165 return VINF_SUCCESS;
1166 }
1167 else
1168 LogRel((DEVICE_NAME ":vboxNetFltSolarisCreateVNIC vboxNetFltSolarisInitVNIC failed. rc=%d\n", rc));
1169
1170 mac_close(pVNIC->hInterface);
1171 pVNIC->hInterface = NULL;
1172 }
1173 else
1174 {
1175 LogRel((DEVICE_NAME ":vboxNetFltSolarisCreateVNIC failed to open VNIC '%s' over '%s'. rc=%d\n", pVNIC->szName,
1176 pThis->szName, rc));
1177 }
1178
1179 vboxNetFltSolarisDestroyVNIC(pVNIC);
1180 rc = VERR_INTNET_FLT_VNIC_CREATE_FAILED;
1181 }
1182 else
1183 {
1184 RTSemFastMutexRelease(g_VBoxNetFltSolarisMtx);
1185
1186 LogRel((DEVICE_NAME ":vboxNetFltSolarisCreateVNIC failed to create VNIC '%s' over '%s' rc=%d Diag=%d\n", pVNIC->szName,
1187 pszLinkName, rc, Diag));
1188 rc = VERR_INTNET_FLT_VNIC_CREATE_FAILED;
1189 }
1190
1191 vboxNetFltSolarisFreeVNIC(pVNIC);
1192
1193 return rc;
1194}
1195
1196
1197/**
1198 * Wrapper for getting the datalink ID given the MAC name.
1199 *
1200 * @param pszMacName The MAC name.
1201 * @param pLinkId Where to store the datalink ID.
1202 *
1203 * @returns VBox status code.
1204 */
1205LOCAL inline int vboxNetFltSolarisGetLinkId(const char *pszMacName, datalink_id_t *pLinkId)
1206{
1207 /*
1208 * dls_mgmt_get_linkid() requires to be in a state to answer upcalls. We should always use this
1209 * first before resorting to other means to retrieve the MAC name.
1210 */
1211 int rc = dls_mgmt_get_linkid(pszMacName, pLinkId);
1212 if (rc)
1213 rc = dls_devnet_macname2linkid(pszMacName, pLinkId);
1214
1215 if (RT_LIKELY(!rc))
1216 return VINF_SUCCESS;
1217
1218 LogRel((DEVICE_NAME ":vboxNetFltSolarisGetLinkId failed for '%s'. rc=%d\n", pszMacName, rc));
1219 return RTErrConvertFromErrno(rc);
1220}
1221
1222
1223/**
1224 * Set the promiscuous mode RX hook.
1225 *
1226 * @param pThis The VM connection instance.
1227 * @param pVNIC Pointer to the VNIC.
1228 *
1229 * @returns VBox status code.
1230 */
1231LOCAL inline int vboxNetFltSolarisSetPromisc(PVBOXNETFLTINS pThis, PVBOXNETFLTVNIC pVNIC)
1232{
1233 int rc = VINF_SUCCESS;
1234 if (!pVNIC->hPromisc)
1235 {
1236 rc = mac_promisc_add(pVNIC->hClient, MAC_CLIENT_PROMISC_FILTERED, vboxNetFltSolarisRecv, pThis, &pVNIC->hPromisc,
1237 MAC_PROMISC_FLAGS_NO_TX_LOOP | MAC_PROMISC_FLAGS_VLAN_TAG_STRIP | MAC_PROMISC_FLAGS_NO_PHYS);
1238 if (RT_UNLIKELY(rc))
1239 LogRel((DEVICE_NAME ":vboxNetFltSolarisSetPromisc failed. rc=%d\n", rc));
1240 rc = RTErrConvertFromErrno(rc);
1241 }
1242 return rc;
1243}
1244
1245
1246/**
1247 * Clear the promiscuous mode RX hook.
1248 *
1249 * @param pThis The VM connection instance.
1250 * @param pVNIC Pointer to the VNIC.
1251 */
1252LOCAL inline void vboxNetFltSolarisRemovePromisc(PVBOXNETFLTINS pThis, PVBOXNETFLTVNIC pVNIC)
1253{
1254 if (pVNIC->hPromisc)
1255 {
1256 mac_promisc_remove(pVNIC->hPromisc);
1257 pVNIC->hPromisc = NULL;
1258 }
1259}
1260
1261
1262/* -=-=-=-=-=- Common Hooks -=-=-=-=-=- */
1263
1264
1265void vboxNetFltPortOsSetActive(PVBOXNETFLTINS pThis, bool fActive)
1266{
1267 Log((DEVICE_NAME ":vboxNetFltPortOsSetActive pThis=%p fActive=%d\n", pThis, fActive));
1268
1269 /*
1270 * Reactivate/quiesce the interface.
1271 */
1272 PVBOXNETFLTVNIC pVNIC = list_head(&pThis->u.s.hVNICs);
1273 if (fActive)
1274 {
1275 for (; pVNIC != NULL; pVNIC = list_next(&pThis->u.s.hVNICs, pVNIC))
1276 if (pVNIC->hClient)
1277 {
1278#if 0
1279 mac_rx_set(pVNIC->hClient, vboxNetFltSolarisRecv, pThis);
1280#endif
1281 vboxNetFltSolarisSetPromisc(pThis, pVNIC);
1282 }
1283 }
1284 else
1285 {
1286 for (; pVNIC != NULL; pVNIC = list_next(&pThis->u.s.hVNICs, pVNIC))
1287 if (pVNIC->hClient)
1288 {
1289#if 0
1290 mac_rx_clear(pVNIC->hClient);
1291#endif
1292 vboxNetFltSolarisRemovePromisc(pThis, pVNIC);
1293 }
1294 }
1295}
1296
1297
1298int vboxNetFltOsDisconnectIt(PVBOXNETFLTINS pThis)
1299{
1300 Log((DEVICE_NAME ":vboxNetFltOsDisconnectIt pThis=%p\n", pThis));
1301 return VINF_SUCCESS;
1302}
1303
1304
1305int vboxNetFltOsConnectIt(PVBOXNETFLTINS pThis)
1306{
1307 Log((DEVICE_NAME ":vboxNetFltOsConnectIt pThis=%p\n", pThis));
1308 return VINF_SUCCESS;
1309}
1310
1311
1312void vboxNetFltOsDeleteInstance(PVBOXNETFLTINS pThis)
1313{
1314 Log((DEVICE_NAME ":vboxNetFltOsDeleteInstance pThis=%p\n", pThis));
1315
1316 if (pThis->u.s.hNotify)
1317 mac_notify_remove(pThis->u.s.hNotify, B_TRUE /* Wait */);
1318
1319 /*
1320 * Destroy all managed VNICs. If a VNIC was passed to us, there
1321 * will be only 1 item in the list, otherwise as many interfaces
1322 * that were somehow not destroyed using DisconnectInterface() will be
1323 * present.
1324 */
1325 PVBOXNETFLTVNIC pVNIC = NULL;
1326 while ((pVNIC = list_remove_head(&pThis->u.s.hVNICs)) != NULL)
1327 {
1328 vboxNetFltSolarisDestroyVNIC(pVNIC);
1329 vboxNetFltSolarisFreeVNIC(pVNIC);
1330 }
1331
1332 list_destroy(&pThis->u.s.hVNICs);
1333}
1334
1335
1336int vboxNetFltOsInitInstance(PVBOXNETFLTINS pThis, void *pvContext)
1337{
1338 Log((DEVICE_NAME ":vboxNetFltOsInitInstance pThis=%p pvContext=%p\n", pThis, pvContext));
1339
1340 /*
1341 * Figure out if the interface is a VNIC or a physical/etherstub/whatever NIC, then
1342 * do the actual VNIC creation if necessary in vboxNetFltPortOsConnectInterface().
1343 */
1344 mac_handle_t hInterface;
1345 int rc = mac_open_by_linkname(pThis->szName, &hInterface);
1346 if (RT_LIKELY(!rc))
1347 {
1348 rc = mac_is_vnic(hInterface);
1349 if (!rc)
1350 {
1351 Log((DEVICE_NAME ":vboxNetFltOsInitInstance pThis=%p physical interface '%s' detected.\n", pThis, pThis->szName));
1352 pThis->u.s.fIsVNIC = false;
1353 }
1354 else
1355 {
1356 pThis->u.s.fIsVNIC = true;
1357 if (RTStrNCmp(pThis->szName, VBOXBOW_VNIC_TEMPLATE_NAME, sizeof(VBOXBOW_VNIC_TEMPLATE_NAME) - 1) == 0)
1358 {
1359 Log((DEVICE_NAME ":vboxNetFltOsInitInstance pThis=%p VNIC template '%s' detected.\n", pThis, pThis->szName));
1360 pThis->u.s.fIsVNICTemplate = true;
1361 }
1362 }
1363
1364 if ( pThis->u.s.fIsVNIC
1365 && !pThis->u.s.fIsVNICTemplate)
1366 Log((DEVICE_NAME ":vboxNetFltOsInitInstance pThis=%p VNIC '%s' detected.\n", pThis, pThis->szName));
1367
1368 /*
1369 * Report info. (host MAC address, promiscuous, GSO capabilities etc.) to IntNet.
1370 */
1371 rc = vboxNetFltSolarisReportInfo(pThis, hInterface, pThis->u.s.fIsVNIC);
1372 if (RT_FAILURE(rc))
1373 LogRel((DEVICE_NAME ":vboxNetFltOsInitInstance failed to report info. rc=%d\n", rc));
1374
1375 mac_close(hInterface);
1376 }
1377 else
1378 {
1379 LogRel((DEVICE_NAME ":vboxNetFltOsInitInstance failed to open link '%s'! rc=%d\n", pThis->szName, rc));
1380 rc = VERR_INTNET_FLT_IF_FAILED;
1381 }
1382
1383 return rc;
1384}
1385
1386
1387int vboxNetFltOsPreInitInstance(PVBOXNETFLTINS pThis)
1388{
1389 /*
1390 * Init. the solaris specific data.
1391 */
1392 pThis->u.s.fIsVNIC = false;
1393 pThis->u.s.fIsVNICTemplate = false;
1394 list_create(&pThis->u.s.hVNICs, sizeof(VBOXNETFLTVNIC), offsetof(VBOXNETFLTVNIC, hNode));
1395 pThis->u.s.hNotify = NULL;
1396 RT_ZERO(pThis->u.s.MacAddr);
1397 return VINF_SUCCESS;
1398}
1399
1400
1401bool vboxNetFltOsMaybeRediscovered(PVBOXNETFLTINS pThis)
1402{
1403 /*
1404 * @todo Think about this.
1405 */
1406 return false;
1407}
1408
1409
1410int vboxNetFltPortOsXmit(PVBOXNETFLTINS pThis, void *pvIfData, PINTNETSG pSG, uint32_t fDst)
1411{
1412 /*
1413 * Validate parameters.
1414 */
1415 PVBOXNETFLTVNIC pVNIC = pvIfData;
1416 AssertReturn(VALID_PTR(pVNIC), VERR_INVALID_POINTER);
1417 AssertMsgReturn(pVNIC->u32Magic == VBOXNETFLTVNIC_MAGIC,
1418 ("Invalid magic=%#x (expected %#x)\n", pVNIC->u32Magic, VBOXNETFLTVNIC_MAGIC),
1419 VERR_INVALID_MAGIC);
1420
1421 /*
1422 * Xmit the packet down the appropriate VNIC interface.
1423 */
1424 int rc = VINF_SUCCESS;
1425 mblk_t *pMsg = vboxNetFltSolarisMBlkFromSG(pThis, pSG, fDst);
1426 if (RT_LIKELY(pMsg))
1427 {
1428 Log((DEVICE_NAME ":vboxNetFltPortOsXmit pThis=%p cbData=%d\n", pThis, MBLKL(pMsg)));
1429
1430 mac_tx_cookie_t pXmitCookie = mac_tx(pVNIC->hClient, pMsg, 0 /* Hint */, MAC_DROP_ON_NO_DESC, NULL /* return message */);
1431 if (RT_LIKELY(!pXmitCookie))
1432 return VINF_SUCCESS;
1433
1434 pMsg = NULL;
1435 rc = VERR_NET_IO_ERROR;
1436 LogRel((DEVICE_NAME ":vboxNetFltPortOsXmit Xmit failed pVNIC=%p.\n", pVNIC));
1437 }
1438 else
1439 {
1440 LogRel((DEVICE_NAME ":vboxNetFltPortOsXmit no memory for allocating Xmit packet.\n"));
1441 rc = VERR_NO_MEMORY;
1442 }
1443
1444 return rc;
1445}
1446
1447
1448void vboxNetFltPortOsNotifyMacAddress(PVBOXNETFLTINS pThis, void *pvIfData, PCRTMAC pMac)
1449{
1450 Log((DEVICE_NAME ":vboxNetFltPortOSNotifyMacAddress pszIf=%s pszVNIC=%s MAC=%.6Rhxs\n", pThis->szName,
1451 ((PVBOXNETFLTVNIC)pvIfData)->szName, pMac));
1452
1453 /*
1454 * Validate parameters.
1455 */
1456 PVBOXNETFLTVNIC pVNIC = pvIfData;
1457 AssertMsgReturnVoid(VALID_PTR(pVNIC) && pVNIC->u32Magic == VBOXNETFLTVNIC_MAGIC,
1458 ("Invalid pVNIC=%p magic=%#x (expected %#x)\n", pvIfData, VALID_PTR(pVNIC) ? pVNIC->u32Magic : 0, VBOXNETFLTVNIC_MAGIC));
1459 AssertMsgReturnVoid(pVNIC->hLinkId != DATALINK_INVALID_LINKID,
1460 ("Invalid hLinkId pVNIC=%p magic=%#x\n", pVNIC, pVNIC->u32Magic));
1461
1462 /*
1463 * Set the MAC address of the VNIC to the one used by the VM interface.
1464 */
1465 uchar_t au8GuestMac[MAXMACADDRLEN];
1466 bcopy(pMac->au8, au8GuestMac, sizeof(RTMAC));
1467
1468 vnic_mac_addr_type_t AddrType = VNIC_MAC_ADDR_TYPE_FIXED;
1469 vnic_ioc_diag_t Diag = VNIC_IOC_DIAG_NONE;
1470 int MacSlot = 0;
1471 int MacLen = sizeof(RTMAC);
1472
1473 int rc = vnic_modify_addr(pVNIC->hLinkId, &AddrType, &MacLen, au8GuestMac, &MacSlot, 0 /* Mac-Prefix Length */, &Diag);
1474 if (RT_LIKELY(!rc))
1475 {
1476 /*
1477 * Remove existing unicast address, promisc. and the RX hook.
1478 */
1479#if 0
1480 if (pVNIC->hUnicast)
1481 {
1482 mac_rx_clear(pVNIC->hClient);
1483 mac_unicast_remove(pVNIC->hClient, pVNIC->hUnicast);
1484 pVNIC->hUnicast = NULL;
1485 }
1486#endif
1487
1488 if (pVNIC->hPromisc)
1489 {
1490 mac_promisc_remove(pVNIC->hPromisc);
1491 pVNIC->hPromisc = NULL;
1492 }
1493
1494 mac_diag_t MacDiag = MAC_DIAG_NONE;
1495 /* uint16_t uVLANId = pVNIC->pVNICTemplate ? pVNIC->pVNICTemplate->uVLANId : 0; */
1496#if 0
1497 rc = mac_unicast_add(pVNIC->hClient, NULL, MAC_UNICAST_PRIMARY, &pVNIC->hUnicast, 0 /* VLAN Id */, &MacDiag);
1498#endif
1499 if (RT_LIKELY(!rc))
1500 {
1501 rc = vboxNetFltSolarisSetPromisc(pThis, pVNIC);
1502#if 0
1503 if (RT_SUCCESS(rc))
1504 {
1505 /*
1506 * Set the RX receive function.
1507 * This shouldn't be necessary as vboxNetFltPortOsSetActive() will be invoked after this, but in the future,
1508 * if the guest NIC changes MAC address this may not be followed by a vboxNetFltPortOsSetActive() call, so set it here anyway.
1509 */
1510 mac_rx_set(pVNIC->hClient, vboxNetFltSolarisRecv, pThis);
1511 Log((DEVICE_NAME ":vboxNetFltPortOsNotifyMacAddress successfully added unicast address %.6Rhxs\n", pMac));
1512 }
1513 else
1514 LogRel((DEVICE_NAME ":vboxNetFltPortOsNotifyMacAddress failed to set promiscuous mode. rc=%d\n", rc));
1515 mac_unicast_remove(pVNIC->hClient, pVNIC->hUnicast);
1516 pVNIC->hUnicast = NULL;
1517#endif
1518 }
1519 else
1520 LogRel((DEVICE_NAME ":vboxNetFltPortOsNotifyMacAddress failed to add primary unicast address. rc=%d Diag=%d\n", rc, MacDiag));
1521 }
1522 else
1523 {
1524 /*
1525 * They really ought to use EEXIST, but I'm afraid this error comes from the VNIC device driver directly.
1526 * Sequence: vnic_modify_addr()->mac_unicast_primary_set()->mac_update_macaddr() which uses a function pointer
1527 * to the MAC driver (calls mac_vnic_unicast_set() in our case). Documented here if the error code should change we know
1528 * where to look.
1529 */
1530 if (rc == ENOTSUP)
1531 {
1532 LogRel((DEVICE_NAME ":vboxNetFltPortOsNotifyMacAddress: failed! a VNIC with mac %.6Rhxs probably already exists.",
1533 pMac, rc));
1534 LogRel((DEVICE_NAME ":vboxNetFltPortOsNotifyMacAddress: This NIC cannot establish connection. szName=%s szVNIC=%s\n",
1535 pThis->szName, pVNIC->szName));
1536 }
1537 else
1538 LogRel((DEVICE_NAME ":vboxNetFltPortOsNotifyMacAddress failed! mac %.6Rhxs rc=%d Diag=%d\n", pMac, rc, Diag));
1539 }
1540}
1541
1542
1543int vboxNetFltPortOsConnectInterface(PVBOXNETFLTINS pThis, void *pvIf, void **ppvIfData)
1544{
1545 Log((DEVICE_NAME ":vboxNetFltPortOsConnectInterface pThis=%p pvIf=%p\n", pThis, pvIf));
1546
1547 int rc = VINF_SUCCESS;
1548
1549 /*
1550 * If the underlying interface is a physical interface or a VNIC template, we need to create
1551 * a VNIC per guest NIC.
1552 */
1553 if ( !pThis->u.s.fIsVNIC
1554 || pThis->u.s.fIsVNICTemplate)
1555 {
1556 PVBOXNETFLTVNIC pVNIC = NULL;
1557 rc = vboxNetFltSolarisCreateVNIC(pThis, &pVNIC);
1558 if (RT_SUCCESS(rc))
1559 {
1560 /*
1561 * VM Interface<->VNIC association so that we can Xmit/Recv on the right ones.
1562 */
1563 pVNIC->pvIf = pvIf;
1564 *ppvIfData = pVNIC;
1565
1566 /*
1567 * Add the created VNIC to the list of VNICs we manage.
1568 */
1569 list_insert_tail(&pThis->u.s.hVNICs, pVNIC);
1570 return VINF_SUCCESS;
1571 }
1572 else
1573 LogRel((DEVICE_NAME ":vboxNetFltPortOsConnectInterface failed to create VNIC rc=%d\n", rc));
1574 }
1575 else
1576 {
1577 /*
1578 * This is a VNIC passed to us, use it directly.
1579 */
1580 PVBOXNETFLTVNIC pVNIC = vboxNetFltSolarisAllocVNIC();
1581 if (RT_LIKELY(pVNIC))
1582 {
1583 pVNIC->fCreated = false;
1584
1585 rc = mac_open_by_linkname(pThis->szName, &pVNIC->hInterface);
1586 if (!rc)
1587 {
1588 /*
1589 * Obtain the data link ID for this VNIC, it's needed for modifying the MAC address among other things.
1590 */
1591 rc = vboxNetFltSolarisGetLinkId(pThis->szName, &pVNIC->hLinkId);
1592 if (RT_SUCCESS(rc))
1593 {
1594 /*
1595 * Initialize the VNIC and add it to the list of managed VNICs.
1596 */
1597 RTStrPrintf(pVNIC->szName, sizeof(pVNIC->szName), "%s", pThis->szName);
1598 rc = vboxNetFltSolarisInitVNIC(pThis, pVNIC);
1599 if (!rc)
1600 {
1601 pVNIC->pvIf = pvIf;
1602 *ppvIfData = pVNIC;
1603 list_insert_head(&pThis->u.s.hVNICs, pVNIC);
1604 return VINF_SUCCESS;
1605 }
1606 else
1607 LogRel((DEVICE_NAME ":vboxNetFltPortOsConnectInterface failed to initialize VNIC. rc=%d\n", rc));
1608 }
1609 else
1610 LogRel((DEVICE_NAME ":vboxNetFltPortOsConnectInterface failed to get link id for '%s'. rc=%d\n", pThis->szName, rc));
1611 }
1612 else
1613 {
1614 LogRel((DEVICE_NAME ":vboxNetFltPortOsConnectInterface failed to open VNIC '%s'. rc=%d\n", pThis->szName, rc));
1615 rc = VERR_OPEN_FAILED;
1616 }
1617
1618 vboxNetFltSolarisFreeVNIC(pVNIC);
1619 }
1620 else
1621 {
1622 LogRel((DEVICE_NAME ":vboxNetFltOsInitInstance failed to allocate VNIC private data.\n"));
1623 rc = VERR_NO_MEMORY;
1624 }
1625 }
1626
1627 return rc;
1628}
1629
1630
1631int vboxNetFltPortOsDisconnectInterface(PVBOXNETFLTINS pThis, void *pvIfData)
1632{
1633 Log((DEVICE_NAME ":vboxNetFltPortOsDisconnectInterface pThis=%p\n", pThis));
1634
1635 PVBOXNETFLTVNIC pVNIC = pvIfData;
1636 AssertMsgReturn(VALID_PTR(pVNIC) && pVNIC->u32Magic == VBOXNETFLTVNIC_MAGIC,
1637 ("Invalid pvIfData=%p magic=%#x (expected %#x)\n", pvIfData, pVNIC ? pVNIC->u32Magic : 0, VBOXNETFLTVNIC_MAGIC),
1638 VERR_INVALID_POINTER);
1639
1640 /*
1641 * If the underlying interface is not a VNIC, we need to delete the created VNIC.
1642 */
1643 if (!pThis->u.s.fIsVNIC)
1644 {
1645 /*
1646 * Remove the VNIC from the list, destroy and free it.
1647 */
1648 list_remove(&pThis->u.s.hVNICs, pVNIC);
1649 Log((DEVICE_NAME ":vboxNetFltPortOsDisconnectInterface destroying pVNIC=%p\n", pVNIC));
1650 vboxNetFltSolarisDestroyVNIC(pVNIC);
1651 vboxNetFltSolarisFreeVNIC(pVNIC);
1652 }
1653
1654 return VINF_SUCCESS;
1655}
1656
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