Changeset View
Changeset View
Standalone View
Standalone View
sys/dev/wtap/plugins/visibility.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 179 Lines • ▼ Show 20 Lines | del_link(struct visibility_plugin *vis_plugin, struct link *l) | ||||
uint32_t value = 1 << bit; | uint32_t value = 1 << bit; | ||||
map->map[index] = map->map[index] & ~value; | map->map[index] = map->map[index] & ~value; | ||||
mtx_unlock(&vis_plugin->pl_mtx); | mtx_unlock(&vis_plugin->pl_mtx); | ||||
#if 0 | #if 0 | ||||
printf("map->map[index] = %u\n", map->map[index]); | printf("map->map[index] = %u\n", map->map[index]); | ||||
#endif | #endif | ||||
} | } | ||||
static int | |||||
get_link(struct visibility_plugin *vis_plugin, struct vis_map_req *req) | |||||
{ | |||||
struct wtap_hal *hal = vis_plugin->base.wp_hal; | |||||
if (req->id < 0 || req->id >= MAX_NBR_WTAP || | |||||
!isset(hal->hal_devs_set, req->id)) | |||||
return -1; | |||||
memcpy(&req->map, &vis_plugin->pl_node[req->id], sizeof(struct vis_map)); | |||||
return 0; | |||||
} | |||||
int | int | ||||
vis_ioctl(struct cdev *sdev, u_long cmd, caddr_t data, | vis_ioctl(struct cdev *sdev, u_long cmd, caddr_t data, | ||||
int fflag, struct thread *td) | int fflag, struct thread *td) | ||||
{ | { | ||||
struct visibility_plugin *vis_plugin = | struct visibility_plugin *vis_plugin = | ||||
(struct visibility_plugin *) sdev->si_drv1; | (struct visibility_plugin *) sdev->si_drv1; | ||||
struct wtap_hal *hal = vis_plugin->base.wp_hal; | struct wtap_hal *hal = vis_plugin->base.wp_hal; | ||||
struct link l; | struct link l; | ||||
struct vis_map_req *req; | |||||
int op; | int op; | ||||
int error = 0; | int error = 0; | ||||
CURVNET_SET(CRED_TO_VNET(curthread->td_ucred)); | CURVNET_SET(CRED_TO_VNET(curthread->td_ucred)); | ||||
switch(cmd) { | switch(cmd) { | ||||
case VISIOCTLOPEN: | case VISIOCTLSETOPEN: | ||||
op = *(int *)data; | op = *(int *)data; | ||||
if(op == 0) | if(op == 0) | ||||
medium_close(hal->hal_md); | medium_close(hal->hal_md); | ||||
else | else | ||||
medium_open(hal->hal_md); | medium_open(hal->hal_md); | ||||
break; | break; | ||||
case VISIOCTLLINK: | case VISIOCTLSETLINK: | ||||
l = *(struct link *)data; | l = *(struct link *)data; | ||||
if(l.op == 0) | if(l.op == 0) | ||||
del_link(vis_plugin, &l); | del_link(vis_plugin, &l); | ||||
else | else | ||||
add_link(vis_plugin, &l); | add_link(vis_plugin, &l); | ||||
#if 0 | #if 0 | ||||
printf("op=%d, id1=%d, id2=%d\n", l.op, l.id1, l.id2); | printf("op=%d, id1=%d, id2=%d\n", l.op, l.id1, l.id2); | ||||
#endif | #endif | ||||
break; | |||||
case VISIOCTLGETOPEN: | |||||
memcpy(data, &hal->hal_md->open, sizeof(int)); | |||||
break; | |||||
case VISIOCTLGETMAP: | |||||
req = (struct vis_map_req *)data; | |||||
if (get_link(vis_plugin, req) < 0) | |||||
error = EINVAL; | |||||
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; | ||||
} | } |