Skip to content

Commit 308459f

Browse files
authored
Adopt more contemporary terminology (#62)
1 parent 13841a1 commit 308459f

File tree

3 files changed

+69
-75
lines changed

3 files changed

+69
-75
lines changed

README.md

+18-18
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ A userspace tool which supports more user-specific utilization for vwifi.
371371
Aiming to provide more flexibility and customization for users of vwifi.
372372
Currently supporting feature:
373373
* display the status of vwifi driver
374-
* Use netlink socket to communicate with vwifi driver allowing user to configure user-specific block list
374+
* Use netlink socket to communicate with vwifi driver allowing user to configure user-specific deny list
375375

376376
#### Status checking
377377
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:
387387
vwifi status : not loaded
388388
```
389389

390-
#### Blocklist test
391-
vwifi also supports blocklist ability to allow some interfaces to block packets from certain interfaces.
392-
We can use `vwifi-tool` to set or unset blocklist for vwifi, multiple options are explained as below
393-
* `-d` : specify the destination interface for a blocklist pair
394-
* `-s` : specify the source interface for a blocklist pair
395-
* `-c` : `1` means to unset the blocklist in vwifi, default as `0`
390+
#### Denylist test
391+
vwifi also supports denylist ability to allow some interfaces to deny packets from certain interfaces.
392+
We can use `vwifi-tool` to set or unset denylist for vwifi, multiple options are explained as below
393+
* `-d` : specify the destination interface for a denylist pair
394+
* `-s` : specify the source interface for a denylist pair
395+
* `-c` : `1` means to unset the denylist in vwifi, default as `0`
396396

397-
Set the blocklist pair using vwifi-tool like the following
397+
Set the denylist pair using vwifi-tool like the following
398398
```
399399
$ ./vwifi-tool -d vw2 -s vw1
400400
```
401-
You should see the following output, including your blocklist which will be sent to vwifi
401+
You should see the following output, including your denylist which will be sent to vwifi
402402
```
403403
vwifi status : live
404-
blocklist:
405-
vw2 blocks vw1
406-
Configuring blocklist for vwifi...
407-
Message from vwifi: vwifi has received your blocklist
404+
denylist:
405+
vw2 denys vw1
406+
Configuring denylist for vwifi...
407+
Message from vwifi: vwifi has received your denylist
408408
```
409409
Then you can try to do the ping test again
410410
```
@@ -417,18 +417,18 @@ PING 10.0.0.3 (10.0.0.3) 56(84) bytes of data.
417417
--- 10.0.0.3 ping statistics ---
418418
4 packets transmitted, 0 received, 100% packet loss, time 3053ms
419419
```
420-
You can adjust the content of your blacklist and load it into vwifi anytime.
420+
You can adjust the content of your denylist and load it into vwifi anytime.
421421

422-
If you want to unset the blocklist in vwifi, simply add the option `-c` with vwifi-tool
422+
If you want to unset the denylist in vwifi, simply add the option `-c` with vwifi-tool
423423
```
424424
$ ./vwifi-tool -c
425425
```
426426
You'll see the following output
427427
```
428428
vwifi status : live
429-
Unset blocklist for vwifi...
430-
Configuring blocklist for vwifi...
431-
Message from vwifi: vwifi has received your blocklist
429+
Unset denylist for vwifi...
430+
Configuring denylist for vwifi...
431+
Message from vwifi: vwifi has received your denylist
432432
```
433433
## Testing environment (virtio)
434434
Below is our testing environment with virtio feature:

vwifi-tool.c

+26-30
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
#define MAX_PAYLOAD 1024
1111
#define LINE_LENGTH 20
12-
#define MAX_BLOCKLIST_PAIR 5
12+
#define MAX_DENYLIST_PAIR 5
1313
#define VWIFI_STATUS_FILE "/sys/module/vwifi/initstate"
1414

1515

@@ -43,33 +43,29 @@ bool opt_set(int d, int s, int c)
4343

4444
/* Check whether the number of source interfaces matches with the number of
4545
* destination interfaces */
46-
bool blocklist_pair_check(int src_len, int dest_len)
46+
bool denylist_pair_check(int src_len, int dest_len)
4747
{
4848
return src_len == dest_len;
4949
}
5050

51-
/* Copy destination and source interface pair into blocklist buffer */
52-
bool blocklist_make(char *blocklist,
53-
char *dest[],
54-
char *src[],
55-
int blocklist_len)
51+
/* Copy destination and source interface pair into denylist buffer */
52+
bool denylist_make(char *denylist, char *dest[], char *src[], int denylist_len)
5653
{
57-
for (int i = 0; i < blocklist_len; i++) {
54+
for (int i = 0; i < denylist_len; i++) {
5855
char tmp[LINE_LENGTH] = {'\0'};
59-
snprintf(tmp, LINE_LENGTH, "%s %s %s\n", dest[i], "blocks", src[i]);
60-
if (strlen(tmp) + strlen(blocklist) < NLMSG_SPACE(MAX_PAYLOAD))
61-
strcat(blocklist, tmp);
56+
snprintf(tmp, LINE_LENGTH, "%s %s %s\n", dest[i], "denys", src[i]);
57+
if (strlen(tmp) + strlen(denylist) < NLMSG_SPACE(MAX_PAYLOAD))
58+
strcat(denylist, tmp);
6259
else {
63-
printf(
64-
"Error: Blocklist size exceeds the maximum size of buffer\n");
60+
printf("Error: Denylist size exceeds the maximum size of buffer\n");
6561
return false;
6662
}
6763
}
6864
return true;
6965
}
7066

71-
/* Send blocklist to kernel using netlink socket */
72-
bool blocklist_send(char *blocklist)
67+
/* Send denylist to kernel using netlink socket */
68+
bool denylist_send(char *denylist)
7369
{
7470
int sock_fd = socket(PF_NETLINK, SOCK_RAW, NETLINK_USERSOCK);
7571
if (sock_fd < 0) {
@@ -96,7 +92,7 @@ bool blocklist_send(char *blocklist)
9692
nlh->nlmsg_pid = getpid();
9793
nlh->nlmsg_flags = 0;
9894

99-
strncpy(NLMSG_DATA(nlh), blocklist, NLMSG_SPACE(MAX_PAYLOAD));
95+
strncpy(NLMSG_DATA(nlh), denylist, NLMSG_SPACE(MAX_PAYLOAD));
10096

10197
struct iovec iov = {
10298
.iov_base = (void *) nlh,
@@ -110,7 +106,7 @@ bool blocklist_send(char *blocklist)
110106
.msg_iovlen = 1,
111107
};
112108

113-
printf("Configuring blocklist for vwifi...\n");
109+
printf("Configuring denylist for vwifi...\n");
114110
sendmsg(sock_fd, &msg, 0);
115111

116112
recvmsg(sock_fd, &msg, 0);
@@ -123,10 +119,10 @@ bool blocklist_send(char *blocklist)
123119

124120
int main(int argc, char *argv[])
125121
{
126-
/* Get opt arguments from command line to configure blocklist */
127-
char *dest[MAX_BLOCKLIST_PAIR], *src[MAX_BLOCKLIST_PAIR],
128-
blocklist_pair[MAX_BLOCKLIST_PAIR][LINE_LENGTH];
129-
int blocklist_len = 0, dest_len = 0, src_len = 0, clear = 0;
122+
/* Get opt arguments from command line to configure denylist */
123+
char *dest[MAX_DENYLIST_PAIR], *src[MAX_DENYLIST_PAIR],
124+
denylist_pair[MAX_DENYLIST_PAIR][LINE_LENGTH];
125+
int denylist_len = 0, dest_len = 0, src_len = 0, clear = 0;
130126
int c;
131127

132128
while ((c = getopt(argc, argv, "d:s:ch")) != -1) {
@@ -149,7 +145,7 @@ int main(int argc, char *argv[])
149145
printf("The arguments are:\n\n");
150146
printf("\t-d Destination interface name\n");
151147
printf("\t-s Source interface name\n");
152-
printf("\t-c Clear blocklist\n");
148+
printf("\t-c Clear denylist\n");
153149
return 0;
154150
default:
155151
printf("Invalid arguments\n");
@@ -164,27 +160,27 @@ int main(int argc, char *argv[])
164160
if (!opt_set(dest_len, src_len, clear))
165161
return 0;
166162

167-
if (!clear && !blocklist_pair_check(src_len, dest_len)) {
163+
if (!clear && !denylist_pair_check(src_len, dest_len)) {
168164
printf("Destination number doesn't match with Source number\n");
169165
exit(1);
170166
}
171167

172-
blocklist_len =
168+
denylist_len =
173169
clear ? 0
174-
: (dest_len < MAX_BLOCKLIST_PAIR ? dest_len : MAX_BLOCKLIST_PAIR);
170+
: (dest_len < MAX_DENYLIST_PAIR ? dest_len : MAX_DENYLIST_PAIR);
175171

176-
/* Copy blocklist pair into message buffer */
172+
/* Copy denylist pair into message buffer */
177173
char buffer[NLMSG_SPACE(MAX_PAYLOAD)];
178174
memset(buffer, '\0', sizeof(buffer));
179175

180-
if (!blocklist_make(buffer, dest, src, blocklist_len))
176+
if (!denylist_make(buffer, dest, src, denylist_len))
181177
exit(1);
182178

183179
if (!clear)
184-
printf("blocklist:\n%s", buffer);
180+
printf("denylist:\n%s", buffer);
185181

186-
/* Send blocklist buffer to kernel */
187-
if (!blocklist_send(buffer))
182+
/* Send denylist buffer to kernel */
183+
if (!denylist_send(buffer))
188184
exit(1);
189185

190186
return 0;

vwifi.c

+25-27
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ struct vwifi_context {
6666
enum vwifi_state state; /**< indicate the program state */
6767
struct list_head vif_list; /**< maintaining all interfaces */
6868
struct list_head ap_list; /**< maintaining multiple AP */
69-
char *blocklist; /**< maintaining the blocklist */
69+
char *denylist; /**< maintaining the denylist */
7070
};
7171

7272
static DEFINE_SPINLOCK(vif_list_lock);
@@ -164,27 +164,26 @@ MODULE_PARM_DESC(station, "Number of virtual interfaces running in STA mode.");
164164
/* Global context */
165165
static struct vwifi_context *vwifi = NULL;
166166

167-
/* Blocklist content */
168-
#define MAX_BLACKLIST_SIZE 1024
167+
/* Denylist content */
168+
#define MAX_DENYLIST_SIZE 1024
169169

170170
static struct sock *nl_sk = NULL;
171171

172-
static int blocklist_check(char *dest, char *source)
172+
static int denylist_check(char *dest, char *source)
173173
{
174-
if (!vwifi->blocklist || !*(vwifi->blocklist))
174+
if (!vwifi->denylist || !*(vwifi->denylist))
175175
return 0;
176176

177177
char *user_input =
178-
kmalloc(sizeof(char) * (strlen(vwifi->blocklist) + 1), GFP_KERNEL);
179-
strncpy(user_input, vwifi->blocklist, strlen(vwifi->blocklist));
178+
kmalloc(sizeof(char) * (strlen(vwifi->denylist) + 1), GFP_KERNEL);
179+
strncpy(user_input, vwifi->denylist, strlen(vwifi->denylist));
180180

181181
char *token = strsep(&user_input, "\n");
182182
while (token) {
183-
char *blacklist_dest = strsep(&token, " ");
183+
char *denylist_dest = strsep(&token, " ");
184184
strsep(&token, " ");
185-
char *blacklist_source = token;
186-
if (!strcmp(dest, blacklist_dest) &&
187-
!strcmp(source, blacklist_source)) {
185+
char *denylist_source = token;
186+
if (!strcmp(dest, denylist_dest) && !strcmp(source, denylist_source)) {
188187
kfree(user_input);
189188
return 1;
190189
}
@@ -195,28 +194,27 @@ static int blocklist_check(char *dest, char *source)
195194
return 0;
196195
}
197196

198-
static void blocklist_load(char *blist)
197+
static void denylist_load(char *dlist)
199198
{
200-
if (!vwifi->blocklist) {
201-
pr_info("vwifi->blocklist have to be kmalloc first\n");
199+
if (!vwifi->denylist) {
200+
pr_info("vwifi->denylist have to be kmalloc first\n");
202201
return;
203202
}
204-
memset(vwifi->blocklist, '\0',
205-
MAX_BLACKLIST_SIZE); /* clear the blocklist */
206-
strncpy(vwifi->blocklist, blist, strlen(blist));
203+
memset(vwifi->denylist, '\0', MAX_DENYLIST_SIZE); /* clear the denylist */
204+
strncpy(vwifi->denylist, dlist, strlen(dlist));
207205
}
208206

209-
static void blocklist_nl_recv(struct sk_buff *skb)
207+
static void denylist_nl_recv(struct sk_buff *skb)
210208
{
211209
struct nlmsghdr *nlh; /* netlink message header */
212210
int pid;
213211
struct sk_buff *skb_out;
214-
char *msg = "vwifi has received your blocklist";
212+
char *msg = "vwifi has received your denylist";
215213
int msg_size = strlen(msg);
216214

217215
nlh = (struct nlmsghdr *) skb->data;
218216

219-
blocklist_load((char *) nlmsg_data(nlh));
217+
denylist_load((char *) nlmsg_data(nlh));
220218

221219
/* pid of sending process */
222220
pid = nlh->nlmsg_pid;
@@ -236,7 +234,7 @@ static void blocklist_nl_recv(struct sk_buff *skb)
236234
}
237235

238236
static struct netlink_kernel_cfg nl_config = {
239-
.input = blocklist_nl_recv,
237+
.input = denylist_nl_recv,
240238
};
241239

242240
/**
@@ -820,8 +818,8 @@ static netdev_tx_t vwifi_ndo_start_xmit(struct sk_buff *skb,
820818
dest_vif->ndev->dev_addr))
821819
continue;
822820

823-
/* Don't send packet from dest_vif's blocklist */
824-
if (blocklist_check(dest_vif->ndev->name, src_vif->ndev->name))
821+
/* Don't send packet from dest_vif's denylist */
822+
if (denylist_check(dest_vif->ndev->name, src_vif->ndev->name))
825823
continue;
826824

827825
if (__vwifi_ndo_start_xmit(vif, dest_vif, skb))
@@ -833,8 +831,8 @@ static netdev_tx_t vwifi_ndo_start_xmit(struct sk_buff *skb,
833831
list_for_each_entry (dest_vif, &vif->bss_list, bss_list) {
834832
if (ether_addr_equal(eth_hdr->h_dest,
835833
dest_vif->ndev->dev_addr)) {
836-
if (!blocklist_check(dest_vif->ndev->name,
837-
src_vif->ndev->name) &&
834+
if (!denylist_check(dest_vif->ndev->name,
835+
src_vif->ndev->name) &&
838836
__vwifi_ndo_start_xmit(vif, dest_vif, skb))
839837
count++;
840838
break;
@@ -1891,7 +1889,7 @@ static void vwifi_free(void)
18911889
}
18921890
spin_unlock_bh(&vif_list_lock);
18931891

1894-
kfree(vwifi->blocklist);
1892+
kfree(vwifi->denylist);
18951893
kfree(vwifi);
18961894
}
18971895

@@ -2976,7 +2974,7 @@ static int __init vwifi_init(void)
29762974
mutex_init(&vwifi->lock);
29772975
INIT_LIST_HEAD(&vwifi->vif_list);
29782976
INIT_LIST_HEAD(&vwifi->ap_list);
2979-
vwifi->blocklist = kmalloc(sizeof(char) * MAX_BLACKLIST_SIZE, GFP_KERNEL);
2977+
vwifi->denylist = kmalloc(sizeof(char) * MAX_DENYLIST_SIZE, GFP_KERNEL);
29802978

29812979
for (int i = 0; i < station; i++) {
29822980
struct wiphy *wiphy = vwifi_cfg80211_add();

0 commit comments

Comments
 (0)