Changeset 18973 in vbox for trunk/src/VBox/HostDrivers/VBoxNetAdp
- Timestamp:
- Apr 17, 2009 6:59:16 AM (16 years ago)
- svn:sync-xref-src-repo-rev:
- 46057
- Location:
- trunk/src/VBox/HostDrivers/VBoxNetAdp
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostDrivers/VBoxNetAdp/Makefile.kmk
r17256 r18973 24 24 25 25 26 if1of ($(KBUILD_TARGET), solaris darwin )26 if1of ($(KBUILD_TARGET), solaris darwin linux) 27 27 # 28 28 # VBoxNetAdp - Virtual Network Adapter … … 34 34 VBoxNetAdp_INST = $(INST_VBOXNETADP)$(if $(eq $(KBUILD_TARGET),darwin),Contents/MacOS/) 35 35 VBoxNetAdp_NAME.solaris = vboxnet 36 VBoxNetAdp_NAME.linux = vboxnetadp 37 VBoxNetAdp_NOINST.linux = true 36 38 VBoxNetAdp_DEPS.solaris += $(VBOX_SVN_REV_KMK) 37 39 VBoxNetAdp_DEFS = IN_RT_R0 VBOX_SVN_REV=$(VBOX_SVN_REV) IN_SUP_STATIC 40 VBoxNetAdp_DEFS.linux = KBUILD_MODNAME=KBUILD_STR\(vboxnetadp\) KBUILD_BASENAME=KBUILD_STR\(vboxnetadp\) MODULE 38 41 VBoxNetAdp_LDFLAGS.darwin = -v -Wl,-whyload -Wl,-v -Wl,-whatsloaded 39 42 VBoxNetAdp_LDFLAGS.solaris += -N misc/gld -N drv/vboxdrv 43 VBoxNetAdp_INCS.linux := \ 44 $(PATH_ROOT)/src/VBox/Runtime/r0drv/linux 40 45 VBoxNetAdp_INCS = \ 41 46 . … … 44 49 VBoxNetAdp_SOURCES.solaris = \ 45 50 solaris/VBoxNetAdp-solaris.c 51 VBoxNetAdp_SOURCES.linux = \ 52 linux/VBoxNetAdp-linux.c \ 53 VBoxNetAdp.c 46 54 VBoxNetAdp_SOURCES = 47 55 #VBoxNetAdp_SOURCES = \ … … 82 90 endif # darwin 83 91 92 ifeq ($(KBUILD_TARGET),linux) 93 # 94 # Install source files for compliation on Linux. 95 # files_vboxnetadp defines VBOX_VBOXNETADP_SOURCES. 96 # 97 include $(PATH_SUB_CURRENT)/linux/files_vboxnetadp 98 INSTALLS += VBoxNetAdp-src VBoxNetAdp-sh 99 VBoxNetAdp-src_INST = bin/src/vboxnetadp/ 100 VBoxNetAdp-src_MODE = a+r,u+w 101 VBoxNetAdp-src_SOURCES = $(subst ",,$(VBOX_VBOXNETADP_SOURCES)) #" 102 VBoxNetAdp-src_SOURCES+= \ 103 $(if $(VBOX_OSE),,\ 104 $(PATH_VBoxNetAdp-src)/dkms.conf) \ 105 $(PATH_VBoxNetAdp-src)/Makefile 106 VBoxNetAdp-src_CLEAN = \ 107 $(PATH_VBoxNetAdp-src)/dkms.conf \ 108 $(PATH_VBoxNetAdp-src)/Makefile \ 109 $(PATH_TARGET)/VBoxNetAdp-src-1.dep 110 111 VBoxNetAdp-sh_INST = bin/src/vboxnetadp/ 112 VBoxNetAdp-sh_MODE = a+rx,u+w 113 VBoxNetAdp-sh_SOURCES = \ 114 $(PATH_VBoxNetAdp-sh)/build_in_tmp \ 115 $(if $(VBOX_OSE),,\ 116 $(PATH_ROOT)/src/VBox/HostDrivers/linux/do_Module.symvers) 117 VBoxNetAdp-sh_CLEAN = $(PATH_VBoxNetAdp-sh)/build_in_tmp 118 119 120 includedep $(PATH_TARGET)/VBoxNetAdp-src-1.dep 121 $$(PATH_VBoxNetAdp-src)/Makefile: \ 122 $(PATH_SUB_CURRENT)/linux/Makefile \ 123 $$(if $$(eq $$(VBoxNetAdp/linux/Makefile_VBOX_HARDENED),$$(VBOX_WITH_HARDENING)),,FORCE) \ 124 | $$(dir $$@) 125 ifndef VBOX_WITH_HARDENING 126 $(QUIET)$(SED) -e "s;-DVBOX_WITH_HARDENING;;g" --output $@ $< 127 else 128 $(QUIET)$(CP) -f $< $@ 129 endif 130 %$(QUIET2)$(RM) -f -- $(PATH_TARGET)/VBoxNetAdp-src-1.dep 131 %$(QUIET2)$(APPEND) '$(PATH_TARGET)/VBoxNetAdp-src-1.dep' 'VBoxNetAdp/linux/Makefile_VBOX_HARDENED=$(VBOX_WITH_HARDENING)' 132 133 ## Scripts needed for building the kernel modules 134 135 $$(PATH_VBoxNetAdp-sh)/build_in_tmp: \ 136 $(PATH_ROOT)/src/VBox/HostDrivers/linux/build_in_tmp \ 137 $(VBOX_VERSION_STAMP) \ 138 | $$(dir $$@) 139 $(call MSG_TOOL,Creating,,$@) 140 $(QUIET)$(SED) -e "s;_VERSION_;${VBOX_VERSION_STRING};g; s;_MODULE_;vboxnetadp;g" --output $@ $< 141 $(QUIET)chmod 0755 $@ 142 143 $$(PATH_VBoxNetAdp-src)/dkms.conf: \ 144 $(PATH_SUB_CURRENT)/linux/dkms.conf \ 145 $(VBOX_VERSION_STAMP) \ 146 | $$(dir $$@) 147 $(call MSG_TOOL,Creating,,$@) 148 $(QUIET)$(SED) -e "s;_VERSION_;${VBOX_VERSION_STRING};g" --output $@ $< 149 150 endif # linux 151 84 152 include $(KBUILD_PATH)/subfooter.kmk 85 153 -
trunk/src/VBox/HostDrivers/VBoxNetAdp/VBoxNetAdp.c
r17198 r18973 36 36 #include "VBoxNetAdpInternal.h" 37 37 38 #include <VBox/sup.h>39 38 #include <VBox/log.h> 40 39 #include <VBox/err.h> 40 #include <iprt/string.h> 41 42 #ifdef VBOXANETADP_DO_NOT_USE_NETFLT 43 44 #include <VBox/sup.h> 41 45 #include <iprt/assert.h> 42 #include <iprt/string.h>43 46 #include <iprt/spinlock.h> 44 47 #include <iprt/uuid.h> … … 1119 1122 } 1120 1123 1124 #else /* !VBOXANETADP_DO_NOT_USE_NETFLT */ 1125 1126 1127 VBOXNETADP g_aAdapters[VBOXNETADP_MAX_INSTANCES]; 1128 1129 1130 1131 /** 1132 * Generate a suitable MAC address. 1133 * 1134 * @param pThis The instance. 1135 * @param pMac Where to return the MAC address. 1136 */ 1137 DECLHIDDEN(void) vboxNetAdpComposeMACAddress(PVBOXNETADP pThis, PRTMAC pMac) 1138 { 1139 /* Use a locally administered version of the OUI we use for the guest NICs. */ 1140 pMac->au8[0] = 0x08 | 2; 1141 pMac->au8[1] = 0x00; 1142 pMac->au8[2] = 0x27; 1143 1144 pMac->au8[3] = 0; /* pThis->uUnit >> 16; */ 1145 pMac->au8[4] = 0; /* pThis->uUnit >> 8; */ 1146 pMac->au8[5] = pThis->uUnit; 1147 } 1148 1149 int vboxNetAdpCreate (PVBOXNETADP *ppNew) 1150 { 1151 int rc; 1152 unsigned i; 1153 for (i = 0; i < RT_ELEMENTS(g_aAdapters); i++) 1154 { 1155 PVBOXNETADP pThis = &g_aAdapters[i]; 1156 1157 if (ASMAtomicCmpXchgU32((uint32_t volatile *)&pThis->enmState, kVBoxNetAdpState_Transitional, kVBoxNetAdpState_Invalid)) 1158 { 1159 RTMAC Mac; 1160 /* Found an empty slot -- use it. */ 1161 Log(("vboxNetAdpCreate: found empty slot: %d\n", i)); 1162 vboxNetAdpComposeMACAddress(pThis, &Mac); 1163 rc = vboxNetAdpOsCreate(pThis, &Mac); 1164 Log(("vboxNetAdpCreate: pThis=%p pThis->szName=%p\n", pThis, pThis->szName)); 1165 if (RT_SUCCESS(rc)) 1166 { 1167 *ppNew = pThis; 1168 ASMAtomicWriteU32((uint32_t volatile *)&pThis->enmState, kVBoxNetAdpState_Active); 1169 } 1170 else 1171 { 1172 ASMAtomicWriteU32((uint32_t volatile *)&pThis->enmState, kVBoxNetAdpState_Invalid); 1173 Log(("vboxNetAdpCreate: vboxNetAdpOsCreate failed with '%Rrc'.\n", rc)); 1174 } 1175 Log2(("VBoxNetAdpCreate: Created %s\n", g_aAdapters[i].szName)); 1176 for (i = 0; i < RT_ELEMENTS(g_aAdapters); i++) 1177 Log2(("VBoxNetAdpCreate: Scanning entry: state=%d name=%s\n", g_aAdapters[i].enmState, g_aAdapters[i].szName)); 1178 return rc; 1179 } 1180 } 1181 Log(("vboxNetAdpCreate: no empty slots!\n")); 1182 1183 /* All slots in adapter array are busy. */ 1184 return VERR_OUT_OF_RESOURCES; 1185 } 1186 1187 int vboxNetAdpDestroy (PVBOXNETADP pThis) 1188 { 1189 int rc = VINF_SUCCESS; 1190 1191 if (!ASMAtomicCmpXchgU32((uint32_t volatile *)&pThis->enmState, kVBoxNetAdpState_Transitional, kVBoxNetAdpState_Active)) 1192 return VERR_INTNET_FLT_IF_BUSY; 1193 1194 vboxNetAdpOsDestroy(pThis); 1195 1196 ASMAtomicWriteU32((uint32_t volatile *)&pThis->enmState, kVBoxNetAdpState_Invalid); 1197 1198 return rc; 1199 } 1200 1201 int vboxNetAdpInit(void) 1202 { 1203 unsigned i; 1204 PVBOXNETADP pVboxnet0; 1205 /* 1206 * Init common members and call OS-specific init. 1207 */ 1208 for (i = 0; i < RT_ELEMENTS(g_aAdapters); i++) 1209 { 1210 g_aAdapters[i].enmState = kVBoxNetAdpState_Invalid; 1211 g_aAdapters[i].uUnit = i; 1212 vboxNetAdpOsInit(&g_aAdapters[i]); 1213 } 1214 1215 /* Create vboxnet0 */ 1216 return vboxNetAdpCreate(&pVboxnet0); 1217 } 1218 1219 /** 1220 * Finds an adapter by its name. 1221 * 1222 * @returns Pointer to the instance by the given name. NULL if not found. 1223 * @param pGlobals The globals. 1224 * @param pszName The name of the instance. 1225 */ 1226 PVBOXNETADP vboxNetAdpFindByName(const char *pszName) 1227 { 1228 unsigned i; 1229 1230 for (i = 0; i < RT_ELEMENTS(g_aAdapters); i++) 1231 { 1232 PVBOXNETADP pThis = &g_aAdapters[i]; 1233 Log2(("VBoxNetAdp: Scanning entry: state=%d name=%s\n", pThis->enmState, pThis->szName)); 1234 if (strncmp(pThis->szName, pszName, VBOXNETADP_MAX_NAME_LEN) == 0) 1235 if (ASMAtomicReadU32((uint32_t volatile *)&pThis->enmState) == kVBoxNetAdpState_Active) 1236 return pThis; 1237 } 1238 return NULL; 1239 } 1240 1241 void vboxNetAdpShutdown(void) 1242 { 1243 unsigned i; 1244 1245 /* Remove virtual adapters */ 1246 for (i = 0; i < RT_ELEMENTS(g_aAdapters); i++) 1247 vboxNetAdpDestroy(&g_aAdapters[i]); 1248 } 1249 #endif /* !VBOXANETADP_DO_NOT_USE_NETFLT */ -
trunk/src/VBox/HostDrivers/VBoxNetAdp/VBoxNetAdpInternal.h
r18863 r18973 123 123 #endif /* !VBOXANETADP_DO_NOT_USE_NETFLT */ 124 124 /** Corresponds to the digit at the end of device name. */ 125 uint 8_tuUnit;125 uint32_t uUnit; 126 126 127 127 union … … 141 141 /** Protocol families attached to this adapter. */ 142 142 protocol_family_t aAttachedFamilies[VBOXNETADP_MAX_FAMILIES]; 143 /** @} */ 144 # elif defined(RT_OS_LINUX) 145 /** @name Darwin instance data. 146 * @{ */ 147 /** Pointer to Linux network device structure. */ 148 struct net_device *pNetDev; 149 /** @} */ 143 150 # else 144 151 # error PORTME … … 154 161 # endif 155 162 #elif defined(RT_OS_LINUX) 156 uint8_t abPadding[ 320];163 uint8_t abPadding[64]; 157 164 #else 158 165 uint8_t abPadding[64]; … … 165 172 typedef VBOXNETADP *PVBOXNETADP; 166 173 174 DECLHIDDEN(int) vboxNetAdpInit(void); 175 DECLHIDDEN(void) vboxNetAdpShutdown(void); 176 DECLHIDDEN(int) vboxNetAdpCreate (PVBOXNETADP *ppNew); 177 DECLHIDDEN(int) vboxNetAdpDestroy(PVBOXNETADP pThis); 178 DECLHIDDEN(PVBOXNETADP) vboxNetAdpFindByName(const char *pszName); 179 167 180 #ifdef VBOXANETADP_DO_NOT_USE_NETFLT 168 181 /** … … 288 301 DECLHIDDEN(int) vboxNetAdpOsConnectIt(PVBOXNETADP pThis); 289 302 303 /** @} */ 304 #endif /* !VBOXANETADP_DO_NOT_USE_NETFLT */ 305 290 306 /** 291 307 * This is called to perform OS-specific structure initializations. … … 320 336 DECLHIDDEN(int) vboxNetAdpOsCreate(PVBOXNETADP pThis, PCRTMAC pMac); 321 337 322 /** @} */323 #endif /* !VBOXANETADP_DO_NOT_USE_NETFLT */324 338 325 339
Note:
See TracChangeset
for help on using the changeset viewer.