From 5379c0c5844be191954b0833192aede85f173a6c Mon Sep 17 00:00:00 2001 From: Vadim Vetrov Date: Mon, 22 Jul 2024 00:14:11 +0300 Subject: [PATCH] Implement raw socket mask handling on application layer. --- youtubeUnblock.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/youtubeUnblock.c b/youtubeUnblock.c index 5b35b93..7098fa7 100644 --- a/youtubeUnblock.c +++ b/youtubeUnblock.c @@ -199,9 +199,8 @@ static int fallback_accept_packet(uint32_t id) { perror("mnl_socket_send"); return MNL_CB_ERROR; } - - return MNL_CB_OK; + return MNL_CB_OK; } #define TLS_CONTENT_TYPE_HANDSHAKE 0x16 @@ -558,6 +557,7 @@ static int queue_cb(const struct nlmsghdr *nlh, void *data) { perror("Metaheader not set"); return MNL_CB_ERROR; } + ph = mnl_attr_get_payload(attr[NFQA_PACKET_HDR]); @@ -580,6 +580,14 @@ static int queue_cb(const struct nlmsghdr *nlh, void *data) { return fallback_accept_packet(packet.id); } + if (attr[NFQA_MARK] != NULL) { + // Skip packets sent by rawsocket to escape infinity loop. + if (ntohl(mnl_attr_get_u32(attr[NFQA_MARK])) == + RAWSOCKET_MARK) { + return fallback_accept_packet(packet.id); + } + } + return process_packet(packet); }