From 35deeccac080161e1992d48bc2e9ed0810b759f9 Mon Sep 17 00:00:00 2001 From: elian Date: Wed, 15 May 2024 15:56:47 +0800 Subject: [PATCH] Adopt more contemporary terminology Replace "blocklist" and "blacklist" with "denylist" --- README.md | 36 +++++++++++++++++------------------ vwifi-tool.c | 54 ++++++++++++++++++++++++++-------------------------- vwifi.c | 52 +++++++++++++++++++++++++------------------------- 3 files changed, 71 insertions(+), 71 deletions(-) diff --git a/README.md b/README.md index 90371c1..0be0b9d 100644 --- a/README.md +++ b/README.md @@ -371,7 +371,7 @@ A userspace tool which supports more user-specific utilization for vwifi. Aiming to provide more flexibility and customization for users of vwifi. Currently supporting feature: * display the status of vwifi driver -* Use netlink socket to communicate with vwifi driver allowing user to configure user-specific block list +* Use netlink socket to communicate with vwifi driver allowing user to configure user-specific deny list #### Status checking We can use `vwifi-tool` to check the status of vwifi driver by executing the following command: @@ -387,24 +387,24 @@ Otherwise, vwifi isn't loaded into kernel yet, the output will be: vwifi status : not loaded ``` -#### Blocklist test -vwifi also supports blocklist ability to allow some interfaces to block packets from certain interfaces. -We can use `vwifi-tool` to set or unset blocklist for vwifi, multiple options are explained as below -* `-d` : specify the destination interface for a blocklist pair -* `-s` : specify the source interface for a blocklist pair -* `-c` : `1` means to unset the blocklist in vwifi, default as `0` +#### Denylist test +vwifi also supports denylist ability to allow some interfaces to deny packets from certain interfaces. +We can use `vwifi-tool` to set or unset denylist for vwifi, multiple options are explained as below +* `-d` : specify the destination interface for a denylist pair +* `-s` : specify the source interface for a denylist pair +* `-c` : `1` means to unset the denylist in vwifi, default as `0` -Set the blocklist pair using vwifi-tool like the following +Set the denylist pair using vwifi-tool like the following ``` $ ./vwifi-tool -d vw2 -s vw1 ``` -You should see the following output, including your blocklist which will be sent to vwifi +You should see the following output, including your denylist which will be sent to vwifi ``` vwifi status : live -blocklist: -vw2 blocks vw1 -Configuring blocklist for vwifi... -Message from vwifi: vwifi has received your blocklist +denylist: +vw2 denys vw1 +Configuring denylist for vwifi... +Message from vwifi: vwifi has received your denylist ``` Then you can try to do the ping test again ``` @@ -417,18 +417,18 @@ PING 10.0.0.3 (10.0.0.3) 56(84) bytes of data. --- 10.0.0.3 ping statistics --- 4 packets transmitted, 0 received, 100% packet loss, time 3053ms ``` -You can adjust the content of your blacklist and load it into vwifi anytime. +You can adjust the content of your denylist and load it into vwifi anytime. -If you want to unset the blocklist in vwifi, simply add the option `-c` with vwifi-tool +If you want to unset the denylist in vwifi, simply add the option `-c` with vwifi-tool ``` $ ./vwifi-tool -c ``` You'll see the following output ``` vwifi status : live -Unset blocklist for vwifi... -Configuring blocklist for vwifi... -Message from vwifi: vwifi has received your blocklist +Unset denylist for vwifi... +Configuring denylist for vwifi... +Message from vwifi: vwifi has received your denylist ``` ## Testing environment (virtio) Below is our testing environment with virtio feature: diff --git a/vwifi-tool.c b/vwifi-tool.c index e4dfa12..93cbd89 100644 --- a/vwifi-tool.c +++ b/vwifi-tool.c @@ -9,7 +9,7 @@ #define MAX_PAYLOAD 1024 #define LINE_LENGTH 20 -#define MAX_BLOCKLIST_PAIR 5 +#define MAX_DENYLIST_PAIR 5 #define VWIFI_STATUS_FILE "/sys/module/vwifi/initstate" @@ -43,33 +43,33 @@ bool opt_set(int d, int s, int c) /* Check whether the number of source interfaces matches with the number of * destination interfaces */ -bool blocklist_pair_check(int src_len, int dest_len) +bool denylist_pair_check(int src_len, int dest_len) { return src_len == dest_len; } -/* Copy destination and source interface pair into blocklist buffer */ -bool blocklist_make(char *blocklist, +/* Copy destination and source interface pair into denylist buffer */ +bool denylist_make(char *denylist, char *dest[], char *src[], - int blocklist_len) + int denylist_len) { - for (int i = 0; i < blocklist_len; i++) { + for (int i = 0; i < denylist_len; i++) { char tmp[LINE_LENGTH] = {'\0'}; - snprintf(tmp, LINE_LENGTH, "%s %s %s\n", dest[i], "blocks", src[i]); - if (strlen(tmp) + strlen(blocklist) < NLMSG_SPACE(MAX_PAYLOAD)) - strcat(blocklist, tmp); + snprintf(tmp, LINE_LENGTH, "%s %s %s\n", dest[i], "denys", src[i]); + if (strlen(tmp) + strlen(denylist) < NLMSG_SPACE(MAX_PAYLOAD)) + strcat(denylist, tmp); else { printf( - "Error: Blocklist size exceeds the maximum size of buffer\n"); + "Error: Denylist size exceeds the maximum size of buffer\n"); return false; } } return true; } -/* Send blocklist to kernel using netlink socket */ -bool blocklist_send(char *blocklist) +/* Send denylist to kernel using netlink socket */ +bool denylist_send(char *denylist) { int sock_fd = socket(PF_NETLINK, SOCK_RAW, NETLINK_USERSOCK); if (sock_fd < 0) { @@ -96,7 +96,7 @@ bool blocklist_send(char *blocklist) nlh->nlmsg_pid = getpid(); nlh->nlmsg_flags = 0; - strncpy(NLMSG_DATA(nlh), blocklist, NLMSG_SPACE(MAX_PAYLOAD)); + strncpy(NLMSG_DATA(nlh), denylist, NLMSG_SPACE(MAX_PAYLOAD)); struct iovec iov = { .iov_base = (void *) nlh, @@ -110,7 +110,7 @@ bool blocklist_send(char *blocklist) .msg_iovlen = 1, }; - printf("Configuring blocklist for vwifi...\n"); + printf("Configuring denylist for vwifi...\n"); sendmsg(sock_fd, &msg, 0); recvmsg(sock_fd, &msg, 0); @@ -123,10 +123,10 @@ bool blocklist_send(char *blocklist) int main(int argc, char *argv[]) { - /* Get opt arguments from command line to configure blocklist */ - char *dest[MAX_BLOCKLIST_PAIR], *src[MAX_BLOCKLIST_PAIR], - blocklist_pair[MAX_BLOCKLIST_PAIR][LINE_LENGTH]; - int blocklist_len = 0, dest_len = 0, src_len = 0, clear = 0; + /* Get opt arguments from command line to configure denylist */ + char *dest[MAX_DENYLIST_PAIR], *src[MAX_DENYLIST_PAIR], + denylist_pair[MAX_DENYLIST_PAIR][LINE_LENGTH]; + int denylist_len = 0, dest_len = 0, src_len = 0, clear = 0; int c; while ((c = getopt(argc, argv, "d:s:ch")) != -1) { @@ -149,7 +149,7 @@ int main(int argc, char *argv[]) printf("The arguments are:\n\n"); printf("\t-d Destination interface name\n"); printf("\t-s Source interface name\n"); - printf("\t-c Clear blocklist\n"); + printf("\t-c Clear denylist\n"); return 0; default: printf("Invalid arguments\n"); @@ -164,27 +164,27 @@ int main(int argc, char *argv[]) if (!opt_set(dest_len, src_len, clear)) return 0; - if (!clear && !blocklist_pair_check(src_len, dest_len)) { + if (!clear && !denylist_pair_check(src_len, dest_len)) { printf("Destination number doesn't match with Source number\n"); exit(1); } - blocklist_len = + denylist_len = clear ? 0 - : (dest_len < MAX_BLOCKLIST_PAIR ? dest_len : MAX_BLOCKLIST_PAIR); + : (dest_len < MAX_DENYLIST_PAIR ? dest_len : MAX_DENYLIST_PAIR); - /* Copy blocklist pair into message buffer */ + /* Copy denylist pair into message buffer */ char buffer[NLMSG_SPACE(MAX_PAYLOAD)]; memset(buffer, '\0', sizeof(buffer)); - if (!blocklist_make(buffer, dest, src, blocklist_len)) + if (!denylist_make(buffer, dest, src, denylist_len)) exit(1); if (!clear) - printf("blocklist:\n%s", buffer); + printf("denylist:\n%s", buffer); - /* Send blocklist buffer to kernel */ - if (!blocklist_send(buffer)) + /* Send denylist buffer to kernel */ + if (!denylist_send(buffer)) exit(1); return 0; diff --git a/vwifi.c b/vwifi.c index 1436687..5d774cb 100644 --- a/vwifi.c +++ b/vwifi.c @@ -66,7 +66,7 @@ struct vwifi_context { enum vwifi_state state; /**< indicate the program state */ struct list_head vif_list; /**< maintaining all interfaces */ struct list_head ap_list; /**< maintaining multiple AP */ - char *blocklist; /**< maintaining the blocklist */ + char *denylist; /**< maintaining the denylist */ }; static DEFINE_SPINLOCK(vif_list_lock); @@ -164,27 +164,27 @@ MODULE_PARM_DESC(station, "Number of virtual interfaces running in STA mode."); /* Global context */ static struct vwifi_context *vwifi = NULL; -/* Blocklist content */ -#define MAX_BLOCKLIST_SIZE 1024 +/* Denylist content */ +#define MAX_DENYLIST_SIZE 1024 static struct sock *nl_sk = NULL; -static int blocklist_check(char *dest, char *source) +static int denylist_check(char *dest, char *source) { - if (!vwifi->blocklist || !*(vwifi->blocklist)) + if (!vwifi->denylist || !*(vwifi->denylist)) return 0; char *user_input = - kmalloc(sizeof(char) * (strlen(vwifi->blocklist) + 1), GFP_KERNEL); - strncpy(user_input, vwifi->blocklist, strlen(vwifi->blocklist)); + kmalloc(sizeof(char) * (strlen(vwifi->denylist) + 1), GFP_KERNEL); + strncpy(user_input, vwifi->denylist, strlen(vwifi->denylist)); char *token = strsep(&user_input, "\n"); while (token) { - char *blacklist_dest = strsep(&token, " "); + char *denylist_dest = strsep(&token, " "); strsep(&token, " "); - char *blacklist_source = token; - if (!strcmp(dest, blacklist_dest) && - !strcmp(source, blacklist_source)) { + char *denylist_source = token; + if (!strcmp(dest, denylist_dest) && + !strcmp(source, denylist_source)) { kfree(user_input); return 1; } @@ -195,28 +195,28 @@ static int blocklist_check(char *dest, char *source) return 0; } -static void blocklist_load(char *blist) +static void denylist_load(char *dlist) { - if (!vwifi->blocklist) { - pr_info("vwifi->blocklist have to be kmalloc first\n"); + if (!vwifi->denylist) { + pr_info("vwifi->denylist have to be kmalloc first\n"); return; } - memset(vwifi->blocklist, '\0', - MAX_BLOCKLIST_SIZE); /* clear the blocklist */ - strncpy(vwifi->blocklist, blist, strlen(blist)); + memset(vwifi->denylist, '\0', + MAX_DENYLIST_SIZE); /* clear the denylist */ + strncpy(vwifi->denylist, dlist, strlen(dlist)); } -static void blocklist_nl_recv(struct sk_buff *skb) +static void denylist_nl_recv(struct sk_buff *skb) { struct nlmsghdr *nlh; /* netlink message header */ int pid; struct sk_buff *skb_out; - char *msg = "vwifi has received your blocklist"; + char *msg = "vwifi has received your denylist"; int msg_size = strlen(msg); nlh = (struct nlmsghdr *) skb->data; - blocklist_load((char *) nlmsg_data(nlh)); + denylist_load((char *) nlmsg_data(nlh)); /* pid of sending process */ pid = nlh->nlmsg_pid; @@ -236,7 +236,7 @@ static void blocklist_nl_recv(struct sk_buff *skb) } static struct netlink_kernel_cfg nl_config = { - .input = blocklist_nl_recv, + .input = denylist_nl_recv, }; /** @@ -820,8 +820,8 @@ static netdev_tx_t vwifi_ndo_start_xmit(struct sk_buff *skb, dest_vif->ndev->dev_addr)) continue; - /* Don't send packet from dest_vif's blocklist */ - if (blocklist_check(dest_vif->ndev->name, src_vif->ndev->name)) + /* Don't send packet from dest_vif's denylist */ + if (denylist_check(dest_vif->ndev->name, src_vif->ndev->name)) continue; if (__vwifi_ndo_start_xmit(vif, dest_vif, skb)) @@ -833,7 +833,7 @@ static netdev_tx_t vwifi_ndo_start_xmit(struct sk_buff *skb, list_for_each_entry (dest_vif, &vif->bss_list, bss_list) { if (ether_addr_equal(eth_hdr->h_dest, dest_vif->ndev->dev_addr)) { - if (!blocklist_check(dest_vif->ndev->name, + if (!denylist_check(dest_vif->ndev->name, src_vif->ndev->name) && __vwifi_ndo_start_xmit(vif, dest_vif, skb)) count++; @@ -1891,7 +1891,7 @@ static void vwifi_free(void) } spin_unlock_bh(&vif_list_lock); - kfree(vwifi->blocklist); + kfree(vwifi->denylist); kfree(vwifi); } @@ -2976,7 +2976,7 @@ static int __init vwifi_init(void) mutex_init(&vwifi->lock); INIT_LIST_HEAD(&vwifi->vif_list); INIT_LIST_HEAD(&vwifi->ap_list); - vwifi->blocklist = kmalloc(sizeof(char) * MAX_BLOCKLIST_SIZE, GFP_KERNEL); + vwifi->denylist = kmalloc(sizeof(char) * MAX_DENYLIST_SIZE, GFP_KERNEL); for (int i = 0; i < station; i++) { struct wiphy *wiphy = vwifi_cfg80211_add();