Changeset View
Changeset View
Standalone View
Standalone View
sys/dev/wtap/if_wtap_module.c
/*- | /*- | ||||
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD | * SPDX-License-Identifier: BSD-2-Clause-FreeBSD | ||||
* | * | ||||
* Copyright (c) 2010-2011 Monthadar Al Jaberi, TerraNet AB | * Copyright (c) 2010-2011 Monthadar Al Jaberi, TerraNet AB | ||||
* All rights reserved. | * All rights reserved. | ||||
* Copyright (c) 2023 The FreeBSD Foundation | |||||
* | * | ||||
* Portions of this software were developed by En-Wei Wu | |||||
* under sponsorship from the FreeBSD Foundation. | |||||
* | |||||
* Redistribution and use in source and binary forms, with or without | * Redistribution and use in source and binary forms, with or without | ||||
* modification, are permitted provided that the following conditions | * modification, are permitted provided that the following conditions | ||||
* are met: | * are met: | ||||
* 1. Redistributions of source code must retain the above copyright | * 1. Redistributions of source code must retain the above copyright | ||||
* notice, this list of conditions and the following disclaimer, | * notice, this list of conditions and the following disclaimer, | ||||
* without modification. | * without modification. | ||||
* 2. Redistributions in binary form must reproduce at minimum a disclaimer | * 2. Redistributions in binary form must reproduce at minimum a disclaimer | ||||
* similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any | * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any | ||||
▲ Show 20 Lines • Show All 89 Lines • ▼ Show 20 Lines | static struct cdevsw wtap_cdevsw = { | ||||
.d_name = "wtapctl", | .d_name = "wtapctl", | ||||
}; | }; | ||||
int | int | ||||
wtap_ioctl(struct cdev *dev, u_long cmd, caddr_t data, | wtap_ioctl(struct cdev *dev, u_long cmd, caddr_t data, | ||||
int fflag, struct thread *td) | int fflag, struct thread *td) | ||||
{ | { | ||||
int error = 0; | int error = 0; | ||||
int id; | |||||
CURVNET_SET(CRED_TO_VNET(curthread->td_ucred)); | CURVNET_SET(CRED_TO_VNET(curthread->td_ucred)); | ||||
switch(cmd) { | switch(cmd) { | ||||
case WTAPIOCTLCRT: | case WTAPIOCTLCRT: | ||||
if(new_wtap(hal, *(int *)data)) | if((id = new_wtap(hal, *(int *)data)) < 0) | ||||
error = EINVAL; | error = EINVAL; | ||||
memcpy(data, &id, sizeof(int)); | |||||
break; | break; | ||||
case WTAPIOCTLDEL: | case WTAPIOCTLDEL: | ||||
if(free_wtap(hal, *(int *)data)) | if(free_wtap(hal, *(int *)data)) | ||||
error = EINVAL; | error = EINVAL; | ||||
break; | |||||
case WTAPIOCTLLIST: | |||||
memcpy(data, &hal->hal_devs_set, sizeof(uint64_t)); | |||||
break; | break; | ||||
default: | default: | ||||
DWTAP_PRINTF("Unknown WTAP IOCTL\n"); | DWTAP_PRINTF("Unknown WTAP IOCTL\n"); | ||||
error = EINVAL; | error = EINVAL; | ||||
} | } | ||||
CURVNET_RESTORE(); | CURVNET_RESTORE(); | ||||
return error; | return error; | ||||
▲ Show 20 Lines • Show All 54 Lines • Show Last 20 Lines |