Skip to content

Commit

Permalink
Cleanup netlink socket on post-nl failure
Browse files Browse the repository at this point in the history
  • Loading branch information
akshayknarayan committed Mar 4, 2021
1 parent 20be1b8 commit 71be9f3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
8 changes: 4 additions & 4 deletions ccp_nl.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ void nl_recv(struct sk_buff *skb) {
int ok;
struct nlmsghdr *nlh = nlmsg_hdr(skb);
if (ccp_msg_reader == NULL) {
pr_info("ccp_msg_reader not ready\n");
pr_info("[ccp] [nl] ccp_msg_reader not ready\n");
return;
}

Expand All @@ -26,7 +26,7 @@ void nl_recv(struct sk_buff *skb) {

ok = ccp_msg_reader(kernel_datapath, (char*)nlmsg_data(nlh), nlh->nlmsg_len);
if (ok < 0) {
pr_info("message read failed: %d.\n", ok);
pr_info("[ccp] [nl] message read failed: %d.\n", ok);
}
}

Expand All @@ -38,7 +38,7 @@ int ccp_nl_sk(ccp_nl_recv_handler msg) {
ccp_msg_reader = msg;
nl_sk = netlink_kernel_create(&init_net, NETLINK_USERSOCK, &cfg);
if (!nl_sk) {
printk(KERN_ALERT "Error creating netlink socket.\n");
printk(KERN_ALERT "[ccp] [nl] Error creating netlink socket.\n");
return -1;
}

Expand Down Expand Up @@ -66,7 +66,7 @@ int nl_sendmsg(
GFP_NOWAIT // @flags: the type of memory to allocate.
);
if (!skb_out) {
printk(KERN_ERR "Failed to allocate new skb\n");
printk(KERN_ERR "[ccp] [nl] Failed to allocate new skb\n");
return -1;
}

Expand Down
6 changes: 6 additions & 0 deletions tcp_ccp.c
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,12 @@ static int __init tcp_ccp_register(void) {

ok = ccp_init(kernel_datapath);
if (ok < 0) {
pr_info("[ccp] ccp_init failed: %d\n", ok);
#if __IPC__ == IPC_NETLINK
free_ccp_nl_sk();
#elif __IPC__ == IPC_CHARDEV
ccpkp_cleanup();
#endif
return -6;
}

Expand Down

0 comments on commit 71be9f3

Please sign in to comment.