From f1ab2ac1a943f7d419c404617b7cce77c83f939b Mon Sep 17 00:00:00 2001 From: Vadim Vetrov Date: Tue, 22 Oct 2024 17:46:02 +0300 Subject: [PATCH] Userspace youtubeUnblock: support kernel versions less than 3.8 The behaviour of nfnetlink_queue is changed since then but old kernels require BIND/UNBIND_PF commands. https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=0360ae412d09bc6f4864c801effcb20bfd84520e Co-Authored-by: renr4 --- youtubeUnblock.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/youtubeUnblock.c b/youtubeUnblock.c index 6e4ee5c..c4106aa 100644 --- a/youtubeUnblock.c +++ b/youtubeUnblock.c @@ -454,6 +454,43 @@ int init_queue(int queue_num) { struct nlmsghdr *nlh; char buf[BUF_SIZE]; + /* Support for kernels versions < 3.8 */ + // Obsolete and ignored in kernel version 3.8 + // https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=0360ae412d09bc6f4864c801effcb20bfd84520e + + nlh = nfq_nlmsg_put(buf, NFQNL_MSG_CONFIG, queue_num); + nfq_nlmsg_cfg_put_cmd(nlh, PF_INET, NFQNL_CFG_CMD_PF_UNBIND); + + if (mnl_socket_sendto(nl, nlh, nlh->nlmsg_len) < 0) { + perror("mnl_socket_send"); + goto die; + } + + nlh = nfq_nlmsg_put(buf, NFQNL_MSG_CONFIG, queue_num); + nfq_nlmsg_cfg_put_cmd(nlh, PF_INET, NFQNL_CFG_CMD_PF_BIND); + + if (mnl_socket_sendto(nl, nlh, nlh->nlmsg_len) < 0) { + perror("mnl_socket_send"); + goto die; + } + + nlh = nfq_nlmsg_put(buf, NFQNL_MSG_CONFIG, queue_num); + nfq_nlmsg_cfg_put_cmd(nlh, PF_INET6, NFQNL_CFG_CMD_PF_UNBIND); + + if (mnl_socket_sendto(nl, nlh, nlh->nlmsg_len) < 0) { + perror("mnl_socket_send"); + goto die; + } + + nlh = nfq_nlmsg_put(buf, NFQNL_MSG_CONFIG, queue_num); + nfq_nlmsg_cfg_put_cmd(nlh, PF_INET6, NFQNL_CFG_CMD_PF_BIND); + + if (mnl_socket_sendto(nl, nlh, nlh->nlmsg_len) < 0) { + perror("mnl_socket_send"); + goto die; + } + /* End of support for kernel versions < 3.8 */ + nlh = nfq_nlmsg_put(buf, NFQNL_MSG_CONFIG, queue_num); nfq_nlmsg_cfg_put_cmd(nlh, AF_INET, NFQNL_CFG_CMD_BIND);