- Timestamp:
- Sep 9, 2009 7:21:32 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Config.kmk
r22859 r22875 497 497 endif 498 498 # Use VBoxNetFlt for host interface networking. 499 if1of ($(KBUILD_TARGET), darwin linux solaris win )499 if1of ($(KBUILD_TARGET), darwin linux solaris win freebsd) 500 500 VBOX_WITH_NETFLT = 1 501 501 VBOX_SOLARIS_NSL_RESOLVED = 1 502 if1of ($(KBUILD_TARGET), darwin solaris linux )502 if1of ($(KBUILD_TARGET), darwin solaris linux freebsd) 503 503 VBOX_WITH_NETADP = 1 504 504 endif … … 688 688 VBOX_WITH_EHCI= 689 689 VBOX_WITH_VMI= 690 ifn1of ($(KBUILD_TARGET), darwin linux solaris win )690 ifn1of ($(KBUILD_TARGET), darwin linux solaris win freebsd) 691 691 VBOX_WITH_NETFLT= 692 692 endif -
trunk/src/VBox/HostDrivers/Makefile.kmk
r18973 r22875 30 30 include $(PATH_SUB_CURRENT)/VBoxUSB/Makefile.kmk 31 31 endif 32 if1of ($(KBUILD_TARGET), darwin solaris win linux )32 if1of ($(KBUILD_TARGET), darwin solaris win linux freebsd) 33 33 ifdef VBOX_WITH_NETFLT 34 34 include $(PATH_SUB_CURRENT)/VBoxNetFlt/Makefile.kmk 35 35 endif 36 36 endif 37 if1of ($(KBUILD_TARGET), darwin solaris linux )37 if1of ($(KBUILD_TARGET), darwin solaris linux freebsd) 38 38 ifdef VBOX_WITH_NETADP 39 39 include $(PATH_SUB_CURRENT)/VBoxNetAdp/Makefile.kmk -
trunk/src/VBox/HostDrivers/VBoxNetAdp/Makefile.kmk
r21948 r22875 24 24 25 25 26 if1of ($(KBUILD_TARGET), solaris darwin linux )26 if1of ($(KBUILD_TARGET), solaris darwin linux freebsd) 27 27 # 28 28 # VBoxNetAdp - Virtual Network Adapter … … 35 35 VBoxNetAdp_NAME.solaris = vboxnet 36 36 VBoxNetAdp_NAME.linux = vboxnetadp 37 VBoxNetAdp_NAME.freebsd = vboxnetadp 37 38 VBoxNetAdp_NOINST.linux = true 38 39 VBoxNetAdp_DEPS.solaris += $(VBOX_SVN_REV_KMK) … … 51 52 VBoxNetAdp_SOURCES.linux = \ 52 53 linux/VBoxNetAdp-linux.c \ 54 VBoxNetAdp.c 55 VBoxNetAdp_SOURCES.freebsd = \ 56 freebsd/VBoxNetAdp-freebsd.c \ 53 57 VBoxNetAdp.c 54 58 VBoxNetAdp_SOURCES = -
trunk/src/VBox/HostDrivers/VBoxNetAdp/VBoxNetAdpInternal.h
r20374 r22875 147 147 /** Pointer to Linux network device structure. */ 148 148 struct net_device *pNetDev; 149 /** @} */ 150 # elif defined(RT_OS_FREEBSD) 151 /** @name FreeBSD instance data. 152 * @{ */ 153 struct ifnet *ifp; 149 154 /** @} */ 150 155 # else -
trunk/src/VBox/HostDrivers/VBoxNetFlt/Makefile.kmk
r22012 r22875 299 299 endif #ifeq ($(KBUILD_TARGET), win) 300 300 301 else if1of ($(KBUILD_TARGET), linux solaris ) ## @todo merge this with the mixed case stuff.301 else if1of ($(KBUILD_TARGET), linux solaris freebsd) ## @todo merge this with the mixed case stuff. 302 302 # 303 303 # vboxnetflt(.ko/.o/) - The lower case driver. … … 328 328 vboxnetflt_SOURCES.linux = linux/VBoxNetFlt-linux.c 329 329 vboxnetflt_SOURCES.solaris = solaris/VBoxNetFlt-solaris.c 330 vboxnetflt_SOURCES.freebsd = freebsd/VBoxNetFlt-freebsd.c 330 331 vboxnetflt_SOURCES = VBoxNetFlt.c 331 332 endif … … 394 395 endif # linux 395 396 397 # Gross hack for FreeBSD 7, should figure this out properly 398 ## @todo Properly generate opt_netgraph.h 399 ifeq ($(KBUILD_TARGET),freebsd) 400 vboxnetflt_DEPS.freebsd += $(PATH_OUT)/opt_netgraph.h 401 $(PATH_OUT)/opt_netgraph.h: 402 echo > $(PATH_OUT)/opt_netgraph.h 403 endif # freebsd 404 396 405 include $(KBUILD_PATH)/subfooter.kmk 397 406 -
trunk/src/VBox/HostDrivers/VBoxNetFlt/VBoxNetFltInternal.h
r22791 r22875 194 194 RTSEMFASTMUTEX hPollMtx; 195 195 /** @} */ 196 # elif defined(RT_OS_FREEBSD) 197 /** @name FreeBSD instance data. 198 * @{ */ 199 /** Interface handle */ 200 struct ifnet *ifp; 201 /** Netgraph node handle */ 202 node_p node; 203 /** Input hook */ 204 hook_p input; 205 /** Output hook */ 206 hook_p output; 207 /** Original interface flags */ 208 unsigned int flags; 209 /** The MAC address of the interface. */ 210 RTMAC Mac; 211 /** @} */ 196 212 # elif defined(RT_OS_WINDOWS) 197 213 /** @name Windows instance data. -
trunk/src/VBox/Main/ConsoleImpl2.cpp
r22867 r22875 77 77 # include <linux/if.h> 78 78 # include <linux/wireless.h> 79 #endif 80 81 #if defined(RT_OS_FREEBSD) && defined(VBOX_WITH_NETFLT) 82 # include <unistd.h> 83 # include <sys/types.h> 84 # include <sys/ioctl.h> 85 # include <sys/socket.h> 86 # include <net/if.h> 79 87 #endif 80 88 … … 2309 2317 /* we're not releasing the INetCfg stuff here since we use it later to figure out whether it is wireless */ 2310 2318 2311 # elif defined(RT_OS_LINUX) 2319 # elif defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD) 2312 2320 /** @todo Check for malformed names. */ 2313 2321 const char *pszTrunk = pszHifName; -
trunk/src/VBox/Main/freebsd/NetIf-freebsd.cpp
r21878 r22875 6 6 /* 7 7 * Copyright (C) 2008 Sun Microsystems, Inc. 8 * Copyright (C) 2009 Fredrik Lindberg <[email protected]> 8 9 * 9 10 * This file is part of VirtualBox Open Source Edition (OSE), as … … 26 27 *******************************************************************************/ 27 28 #define LOG_GROUP LOG_GROUP_MAIN 29 #include <sys/types.h> 30 31 #include <sys/sysctl.h> 32 #include <sys/socket.h> 33 #include <sys/sockio.h> 34 #include <net/if.h> 35 #include <net/if_types.h> 36 37 #include <net/route.h> 38 /* 39 * route.h includes net/radix.h which for some reason defines Free as a wrapper 40 * around free. This collides with Free defined in xpcom/include/nsIMemory.h 41 * Undefine it and hope for the best 42 */ 43 #undef Free 44 45 #include <net/if_dl.h> 46 #include <netinet/in.h> 47 48 #include <stdio.h> 49 #include <unistd.h> 50 #include <errno.h> 51 52 #include <list> 28 53 29 54 #include "HostNetworkInterfaceImpl.h" … … 31 56 #include "Logging.h" 32 57 58 #define ROUNDUP(a) \ 59 ((a) > 0 ? (1 + (((a) - 1) | (sizeof(long) - 1))) : sizeof(long)) 60 #define ADVANCE(x, n) (x += ROUNDUP((n)->sa_len)) 61 62 void extractAddresses(int iAddrMask, caddr_t cp, caddr_t cplim, struct sockaddr **pAddresses) 63 { 64 struct sockaddr *sa; 65 66 for (int i = 0; i < RTAX_MAX && cp < cplim; i++) { 67 if (!(iAddrMask & (1 << i))) 68 continue; 69 70 sa = (struct sockaddr *)cp; 71 72 pAddresses[i] = sa; 73 74 ADVANCE(cp, sa); 75 } 76 } 77 78 static int getDefaultIfaceIndex(unsigned short *pu16Index, int family) 79 { 80 size_t cbNeeded; 81 char *pBuf, *pNext; 82 int aiMib[6]; 83 struct sockaddr *addresses[RTAX_MAX]; 84 aiMib[0] = CTL_NET; 85 aiMib[1] = PF_ROUTE; 86 aiMib[2] = 0; 87 aiMib[3] = family; /* address family */ 88 aiMib[4] = NET_RT_DUMP; 89 aiMib[5] = 0; 90 91 if (sysctl(aiMib, 6, NULL, &cbNeeded, NULL, 0) < 0) 92 { 93 Log(("getDefaultIfaceIndex: Failed to get estimate for list size (errno=%d).\n", errno)); 94 return RTErrConvertFromErrno(errno); 95 } 96 if ((pBuf = (char*)malloc(cbNeeded)) == NULL) 97 return VERR_NO_MEMORY; 98 if (sysctl(aiMib, 6, pBuf, &cbNeeded, NULL, 0) < 0) 99 { 100 free(pBuf); 101 Log(("getDefaultIfaceIndex: Failed to retrieve interface table (errno=%d).\n", errno)); 102 return RTErrConvertFromErrno(errno); 103 } 104 105 char *pEnd = pBuf + cbNeeded; 106 struct rt_msghdr *pRtMsg; 107 for (pNext = pBuf; pNext < pEnd; pNext += pRtMsg->rtm_msglen) 108 { 109 pRtMsg = (struct rt_msghdr *)pNext; 110 111 if (pRtMsg->rtm_type != RTM_GET) 112 { 113 Log(("getDefaultIfaceIndex: Got message %u while expecting %u.\n", 114 pRtMsg->rtm_type, RTM_GET)); 115 //rc = VERR_INTERNAL_ERROR; 116 continue; 117 } 118 if ((char*)(pRtMsg + 1) < pEnd) 119 { 120 /* Extract addresses from the message. */ 121 extractAddresses(pRtMsg->rtm_addrs, (char *)(pRtMsg + 1), 122 pRtMsg->rtm_msglen + (char *)pRtMsg, addresses); 123 if ((pRtMsg->rtm_addrs & RTA_DST)) 124 { 125 if (addresses[RTAX_DST]->sa_family != AF_INET) 126 continue; 127 struct sockaddr_in *addr = (struct sockaddr_in *)addresses[RTAX_DST]; 128 struct sockaddr_in *mask = (struct sockaddr_in *)addresses[RTAX_NETMASK]; 129 if ((addr->sin_addr.s_addr == INADDR_ANY) && 130 mask && 131 (ntohl(mask->sin_addr.s_addr) == 0L || 132 mask->sin_len == 0)) 133 { 134 *pu16Index = pRtMsg->rtm_index; 135 free(pBuf); 136 return VINF_SUCCESS; 137 } 138 } 139 } 140 } 141 free(pBuf); 142 return VERR_INTERNAL_ERROR; 143 144 } 145 146 void extractAddressesToNetInfo(int iAddrMask, caddr_t cp, caddr_t cplim, PNETIFINFO pInfo) 147 { 148 struct sockaddr *addresses[RTAX_MAX]; 149 150 extractAddresses(iAddrMask, cp, cplim, addresses); 151 switch (addresses[RTAX_IFA]->sa_family) 152 { 153 case AF_INET: 154 if (!pInfo->IPAddress.u) 155 { 156 pInfo->IPAddress.u = ((struct sockaddr_in *)addresses[RTAX_IFA])->sin_addr.s_addr; 157 pInfo->IPNetMask.u = ((struct sockaddr_in *)addresses[RTAX_NETMASK])->sin_addr.s_addr; 158 } 159 break; 160 case AF_INET6: 161 if (!pInfo->IPv6Address.s.Lo && !pInfo->IPv6Address.s.Hi) 162 { 163 memcpy(pInfo->IPv6Address.au8, 164 ((struct sockaddr_in6 *)addresses[RTAX_IFA])->sin6_addr.__u6_addr.__u6_addr8, 165 sizeof(pInfo->IPv6Address)); 166 memcpy(pInfo->IPv6NetMask.au8, 167 ((struct sockaddr_in6 *)addresses[RTAX_NETMASK])->sin6_addr.__u6_addr.__u6_addr8, 168 sizeof(pInfo->IPv6NetMask)); 169 } 170 break; 171 default: 172 Log(("NetIfList: Unsupported address family: %u\n", addresses[RTAX_IFA]->sa_family)); 173 break; 174 } 175 } 176 177 33 178 int NetIfList(std::list <ComObjPtr<HostNetworkInterface> > &list) 34 179 { 35 /** @todo implement */ 36 return VERR_NOT_IMPLEMENTED; 180 int rc = VINF_SUCCESS; 181 size_t cbNeeded; 182 char *pBuf, *pNext; 183 int aiMib[6]; 184 unsigned short u16DefaultIface; 185 186 /* Get the index of the interface associated with default route. */ 187 rc = getDefaultIfaceIndex(&u16DefaultIface, PF_INET); 188 if (RT_FAILURE(rc)) 189 return rc; 190 191 aiMib[0] = CTL_NET; 192 aiMib[1] = PF_ROUTE; 193 aiMib[2] = 0; 194 aiMib[3] = 0; /* address family */ 195 aiMib[4] = NET_RT_IFLIST; 196 aiMib[5] = 0; 197 198 if (sysctl(aiMib, 6, NULL, &cbNeeded, NULL, 0) < 0) 199 { 200 Log(("NetIfList: Failed to get estimate for list size (errno=%d).\n", errno)); 201 return RTErrConvertFromErrno(errno); 202 } 203 if ((pBuf = (char*)malloc(cbNeeded)) == NULL) 204 return VERR_NO_MEMORY; 205 if (sysctl(aiMib, 6, pBuf, &cbNeeded, NULL, 0) < 0) 206 { 207 free(pBuf); 208 Log(("NetIfList: Failed to retrieve interface table (errno=%d).\n", errno)); 209 return RTErrConvertFromErrno(errno); 210 } 211 212 int sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP); 213 if (sock < 0) 214 { 215 free(pBuf); 216 Log(("NetIfList: socket() -> %d\n", errno)); 217 return RTErrConvertFromErrno(errno); 218 } 219 220 char *pEnd = pBuf + cbNeeded; 221 for (pNext = pBuf; pNext < pEnd;) 222 { 223 struct if_msghdr *pIfMsg = (struct if_msghdr *)pNext; 224 225 if (pIfMsg->ifm_type != RTM_IFINFO) 226 { 227 Log(("NetIfList: Got message %u while expecting %u.\n", 228 pIfMsg->ifm_type, RTM_IFINFO)); 229 rc = VERR_INTERNAL_ERROR; 230 break; 231 } 232 struct sockaddr_dl *pSdl = (struct sockaddr_dl *)(pIfMsg + 1); 233 234 size_t cbNameLen = pSdl->sdl_nlen + 1; 235 PNETIFINFO pNew = (PNETIFINFO)RTMemAllocZ(RT_OFFSETOF(NETIFINFO, szName[cbNameLen])); 236 if (!pNew) 237 { 238 rc = VERR_NO_MEMORY; 239 break; 240 } 241 memcpy(pNew->MACAddress.au8, LLADDR(pSdl), sizeof(pNew->MACAddress.au8)); 242 pNew->enmMediumType = NETIF_T_ETHERNET; 243 Assert(sizeof(pNew->szShortName) >= cbNameLen); 244 strlcpy(pNew->szShortName, pSdl->sdl_data, cbNameLen); 245 strlcpy(pNew->szName, pSdl->sdl_data, cbNameLen); 246 /* Generate UUID from name and MAC address. */ 247 RTUUID uuid; 248 RTUuidClear(&uuid); 249 memcpy(&uuid, pNew->szShortName, RT_MIN(cbNameLen, sizeof(uuid))); 250 uuid.Gen.u8ClockSeqHiAndReserved = (uuid.Gen.u8ClockSeqHiAndReserved & 0x3f) | 0x80; 251 uuid.Gen.u16TimeHiAndVersion = (uuid.Gen.u16TimeHiAndVersion & 0x0fff) | 0x4000; 252 memcpy(uuid.Gen.au8Node, pNew->MACAddress.au8, sizeof(uuid.Gen.au8Node)); 253 pNew->Uuid = uuid; 254 255 pNext += pIfMsg->ifm_msglen; 256 while (pNext < pEnd) 257 { 258 struct ifa_msghdr *pIfAddrMsg = (struct ifa_msghdr *)pNext; 259 260 if (pIfAddrMsg->ifam_type != RTM_NEWADDR) 261 break; 262 extractAddressesToNetInfo(pIfAddrMsg->ifam_addrs, 263 (char *)(pIfAddrMsg + 1), 264 pIfAddrMsg->ifam_msglen + (char *)pIfAddrMsg, 265 pNew); 266 pNext += pIfAddrMsg->ifam_msglen; 267 } 268 269 if (pSdl->sdl_type == IFT_ETHER) 270 { 271 struct ifreq IfReq; 272 strcpy(IfReq.ifr_name, pNew->szShortName); 273 if (ioctl(sock, SIOCGIFFLAGS, &IfReq) < 0) 274 { 275 Log(("NetIfList: ioctl(SIOCGIFFLAGS) -> %d\n", errno)); 276 pNew->enmStatus = NETIF_S_UNKNOWN; 277 } 278 else 279 pNew->enmStatus = (IfReq.ifr_flags & IFF_UP) ? NETIF_S_UP : NETIF_S_DOWN; 280 281 HostNetworkInterfaceType_T enmType; 282 if (strncmp("vboxnet", pNew->szName, 7)) 283 enmType = HostNetworkInterfaceType_Bridged; 284 else 285 enmType = HostNetworkInterfaceType_HostOnly; 286 287 ComObjPtr<HostNetworkInterface> IfObj; 288 IfObj.createObject(); 289 if (SUCCEEDED(IfObj->init(Bstr(pNew->szName), enmType, pNew))) 290 /* Make sure the default interface gets to the beginning. */ 291 if (pIfMsg->ifm_index == u16DefaultIface) 292 list.push_front(IfObj); 293 else 294 list.push_back(IfObj); 295 } 296 RTMemFree(pNew); 297 } 298 299 close(sock); 300 free(pBuf); 301 return rc; 302 303 37 304 } 305 306 int NetIfGetConfigByName(PNETIFINFO pInfo) 307 { 308 int rc = VINF_SUCCESS; 309 size_t cbNeeded; 310 char *pBuf, *pNext; 311 int aiMib[6]; 312 313 aiMib[0] = CTL_NET; 314 aiMib[1] = PF_ROUTE; 315 aiMib[2] = 0; 316 aiMib[3] = 0; /* address family */ 317 aiMib[4] = NET_RT_IFLIST; 318 aiMib[5] = 0; 319 320 if (sysctl(aiMib, 6, NULL, &cbNeeded, NULL, 0) < 0) 321 { 322 Log(("NetIfList: Failed to get estimate for list size (errno=%d).\n", errno)); 323 return RTErrConvertFromErrno(errno); 324 } 325 if ((pBuf = (char*)malloc(cbNeeded)) == NULL) 326 return VERR_NO_MEMORY; 327 if (sysctl(aiMib, 6, pBuf, &cbNeeded, NULL, 0) < 0) 328 { 329 free(pBuf); 330 Log(("NetIfList: Failed to retrieve interface table (errno=%d).\n", errno)); 331 return RTErrConvertFromErrno(errno); 332 } 333 334 int sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP); 335 if (sock < 0) 336 { 337 free(pBuf); 338 Log(("NetIfList: socket() -> %d\n", errno)); 339 return RTErrConvertFromErrno(errno); 340 } 341 342 char *pEnd = pBuf + cbNeeded; 343 for (pNext = pBuf; pNext < pEnd;) 344 { 345 struct if_msghdr *pIfMsg = (struct if_msghdr *)pNext; 346 347 if (pIfMsg->ifm_type != RTM_IFINFO) 348 { 349 Log(("NetIfList: Got message %u while expecting %u.\n", 350 pIfMsg->ifm_type, RTM_IFINFO)); 351 rc = VERR_INTERNAL_ERROR; 352 break; 353 } 354 struct sockaddr_dl *pSdl = (struct sockaddr_dl *)(pIfMsg + 1); 355 356 bool fSkip = !!strcmp(pInfo->szShortName, pSdl->sdl_data); 357 358 pNext += pIfMsg->ifm_msglen; 359 while (pNext < pEnd) 360 { 361 struct ifa_msghdr *pIfAddrMsg = (struct ifa_msghdr *)pNext; 362 363 if (pIfAddrMsg->ifam_type != RTM_NEWADDR) 364 break; 365 if (!fSkip) 366 extractAddressesToNetInfo(pIfAddrMsg->ifam_addrs, 367 (char *)(pIfAddrMsg + 1), 368 pIfAddrMsg->ifam_msglen + (char *)pIfAddrMsg, 369 pInfo); 370 pNext += pIfAddrMsg->ifam_msglen; 371 } 372 373 if (!fSkip && pSdl->sdl_type == IFT_ETHER) 374 { 375 size_t cbNameLen = pSdl->sdl_nlen + 1; 376 memcpy(pInfo->MACAddress.au8, LLADDR(pSdl), sizeof(pInfo->MACAddress.au8)); 377 pInfo->enmMediumType = NETIF_T_ETHERNET; 378 /* Generate UUID from name and MAC address. */ 379 RTUUID uuid; 380 RTUuidClear(&uuid); 381 memcpy(&uuid, pInfo->szShortName, RT_MIN(cbNameLen, sizeof(uuid))); 382 uuid.Gen.u8ClockSeqHiAndReserved = (uuid.Gen.u8ClockSeqHiAndReserved & 0x3f) | 0x80; 383 uuid.Gen.u16TimeHiAndVersion = (uuid.Gen.u16TimeHiAndVersion & 0x0fff) | 0x4000; 384 memcpy(uuid.Gen.au8Node, pInfo->MACAddress.au8, sizeof(uuid.Gen.au8Node)); 385 pInfo->Uuid = uuid; 386 387 struct ifreq IfReq; 388 strcpy(IfReq.ifr_name, pInfo->szShortName); 389 if (ioctl(sock, SIOCGIFFLAGS, &IfReq) < 0) 390 { 391 Log(("NetIfList: ioctl(SIOCGIFFLAGS) -> %d\n", errno)); 392 pInfo->enmStatus = NETIF_S_UNKNOWN; 393 } 394 else 395 pInfo->enmStatus = (IfReq.ifr_flags & IFF_UP) ? NETIF_S_UP : NETIF_S_DOWN; 396 397 return VINF_SUCCESS; 398 } 399 } 400 close(sock); 401 free(pBuf); 402 return rc; 403 } 404 -
trunk/src/VBox/Main/generic/NetIf-generic.cpp
r22211 r22875 133 133 int NetIfCreateHostOnlyNetworkInterface (VirtualBox *pVBox, IHostNetworkInterface **aHostNetworkInterface, IProgress **aProgress) 134 134 { 135 #if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) 135 #if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD) 136 136 /* create a progress object */ 137 137 ComObjPtr<Progress> progress; … … 218 218 IProgress **aProgress) 219 219 { 220 #if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) 220 #if defined(RT_OS_LINUX) || defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD) 221 221 /* create a progress object */ 222 222 ComObjPtr<Progress> progress; -
trunk/src/apps/Makefile.kmk
r17855 r22875 33 33 endif 34 34 endif 35 if1of ($(KBUILD_TARGET),darwin solaris linux )35 if1of ($(KBUILD_TARGET),darwin solaris linux freebsd) 36 36 ifneq ($(wildcard $(PATH_SUB_CURRENT)/adpctl),) 37 37 include $(PATH_SUB_CURRENT)/adpctl/Makefile.kmk
Note:
See TracChangeset
for help on using the changeset viewer.