From 71be9f3894761549a73df8dfc76fd92d680364ed Mon Sep 17 00:00:00 2001 From: Akshay Narayan Date: Thu, 4 Mar 2021 17:30:29 +0000 Subject: [PATCH] Cleanup netlink socket on post-nl failure --- ccp_nl.c | 8 ++++---- tcp_ccp.c | 6 ++++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/ccp_nl.c b/ccp_nl.c index fa84bf2..6b7ecbc 100644 --- a/ccp_nl.c +++ b/ccp_nl.c @@ -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; } @@ -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); } } @@ -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; } @@ -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; } diff --git a/tcp_ccp.c b/tcp_ccp.c index 3c4048b..3d35d34 100644 --- a/tcp_ccp.c +++ b/tcp_ccp.c @@ -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; }