Changeset 23068 in vbox for trunk/src/VBox/HostDrivers/VBoxNetAdp/linux/VBoxNetAdp-linux.c
- Timestamp:
- Sep 16, 2009 12:59:18 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostDrivers/VBoxNetAdp/linux/VBoxNetAdp-linux.c
r21682 r23068 257 257 { 258 258 VBOXNETADPREQ Req; 259 PVBOXNETADP pAdp = NULL; 260 int rc = VINF_SUCCESS; 261 uint32_t cbReq = _IOC_SIZE(uCmd); 262 263 Log(("VBoxNetAdpLinuxIOCtl: param len %#x; uCmd=%#x; add=%#x\n", cbReq, uCmd, VBOXNETADP_CTL_ADD)); 264 if (RT_UNLIKELY(_IOC_SIZE(uCmd) != sizeof(Req))) 265 { 266 Log(("VBoxNetAdpLinuxIOCtl: bad ioctl sizeof(Req)=%#x _IOC_SIZE=%#x; uCmd=%#x.\n", sizeof(Req), cbReq, uCmd)); 259 PVBOXNETADP pAdp; 260 int rc; 261 262 Log(("VBoxNetAdpLinuxIOCtl: param len %#x; uCmd=%#x; add=%#x\n", _IOC_SIZE(uCmd), uCmd, VBOXNETADP_CTL_ADD)); 263 if (RT_UNLIKELY(_IOC_SIZE(uCmd) != sizeof(Req))) /* paraonia */ 264 { 265 Log(("VBoxNetAdpLinuxIOCtl: bad ioctl sizeof(Req)=%#x _IOC_SIZE=%#x; uCmd=%#x.\n", sizeof(Req), _IOC_SIZE(uCmd), uCmd)); 267 266 return -EINVAL; 268 267 } 268 269 269 switch (uCmd) 270 270 { 271 271 case VBOXNETADP_CTL_ADD: 272 272 Log(("VBoxNetAdpLinuxIOCtl: _IOC_DIR(uCmd)=%#x; IOC_OUT=%#x\n", _IOC_DIR(uCmd), IOC_OUT)); 273 if (uCmd & IOC_OUT)274 {275 rc = vboxNetAdpCreate(&pAdp);276 if (RT_SUCCESS(rc))277 {278 if (cbReq < sizeof(VBOXNETADPREQ))279 { 280 printk(KERN_ERR "VBoxNetAdpLinuxIOCtl: param len %#x < req size %#zx; uCmd=%#x\n", cbReq, sizeof(VBOXNETADPREQ), uCmd);281 return -EINVAL;282 }283 strncpy(Req.szName, pAdp->szName, sizeof(Req.szName)); 284 285 286 287 printk(KERN_ERR "VBoxNetAdpLinuxIOCtl: copy_to_user(%#lx,,%#zx); uCmd=%#x!\n", ulArg, sizeof(Req), uCmd);288 rc = -EFAULT;289 }290 291 }273 rc = vboxNetAdpCreate(&pAdp); 274 if (RT_FAILURE(rc)) 275 { 276 Log(("VBoxNetAdpLinuxIOCtl: vboxNetAdpCreate -> %Rrc\n", rc)); 277 return -EINVAL; 278 } 279 280 Assert(strlen(pAdp->szName) < sizeof(Req.szName)); 281 strncpy(Req.szName, pAdp->szName, sizeof(Req.szName) - 1); 282 Req.szName[sizeof(Req.szName) - 1] = '\0'; 283 284 if (RT_UNLIKELY(copy_to_user((void *)ulArg, &Req, sizeof(Req)))) 285 { 286 /* this is really bad! */ 287 /** @todo remove the adapter again? */ 288 printk(KERN_ERR "VBoxNetAdpLinuxIOCtl: copy_to_user(%#lx,,%#zx); uCmd=%#x!\n", ulArg, sizeof(Req), uCmd); 289 return -EFAULT; 290 } 291 Log(("VBoxNetAdpLinuxIOCtl: Successfully added '%s'\n", Req.szName)); 292 292 break; 293 293 … … 299 299 } 300 300 Log(("VBoxNetAdpLinuxIOCtl: Remove %s\n", Req.szName)); 301 301 302 pAdp = vboxNetAdpFindByName(Req.szName); 302 if (pAdp) 303 rc = vboxNetAdpDestroy(pAdp); 304 else 305 rc = VERR_NOT_FOUND; 303 if (!pAdp) 304 { 305 Log(("VBoxNetAdpLinuxIOCtl: '%s' not found\n", Req.szName)); 306 return -EINVAL; 307 } 308 309 rc = vboxNetAdpDestroy(pAdp); 310 if (RT_FAILURE(rc)) 311 { 312 Log(("VBoxNetAdpLinuxIOCtl: vboxNetAdpDestroy('%s') -> %Rrc\n", Req.szName, rc)); 313 return -EINVAL; 314 } 315 Log(("VBoxNetAdpLinuxIOCtl: Successfully removed '%s'\n", Req.szName)); 306 316 break; 307 317 308 318 default: 309 319 printk(KERN_ERR "VBoxNetAdpLinuxIOCtl: unknown command %x.\n", uCmd); 310 rc = VERR_INVALID_PARAMETER; 311 break; 312 } 313 314 Log(("VBoxNetAdpLinuxIOCtl: rc=%Vrc\n", rc)); 315 return RT_SUCCESS(rc) ? 0 : -EINVAL; 320 return -EINVAL; 321 } 322 323 return 0; 316 324 } 317 325
Note:
See TracChangeset
for help on using the changeset viewer.