forked from destan19/OpenAppFilter
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
72 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#ifndef __AF_BYPASS_H__ | ||
#define __AF_BYPASS_H__ | ||
|
||
static inline int bypassed_interface(struct net_device *in) | ||
{ | ||
if (0 == strncmp(in->name, "br-lan", 6)){ | ||
return 0; | ||
} | ||
else{ | ||
return 1; | ||
} | ||
} | ||
|
||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,4,0) | ||
#define BYPASS_PACKET() (bypass_packet(skb)) | ||
static inline int bypass_packet(struct sk_buff *skb) { | ||
#else | ||
#define BYPASS_PACKET() (bypass_packet(skb, in)) | ||
static inline int bypass_packet(struct sk_buff *skb, const struct net_device *in) { | ||
#endif | ||
int bypassed = 0; | ||
// 4.10-->4.11 nfct-->_nfct | ||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,11,0) | ||
struct nf_conn *ct = (struct nf_conn *)skb->_nfct; | ||
#else | ||
struct nf_conn *ct = (struct nf_conn *)skb->nfct; | ||
#endif | ||
if (ct == NULL) { | ||
return 1; | ||
} | ||
|
||
// for HTTP GET / or HTTPS clien-hello, just a trick | ||
if (skb->len < 67 || skb->len > 1200) | ||
return 1; | ||
|
||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,4,0) | ||
if(!skb->dev) | ||
return 1; | ||
|
||
bypassed = bypassed_interface(skb->dev); | ||
#else | ||
if (!in){ | ||
AF_ERROR("in is NULL\n"); | ||
return 1; | ||
} | ||
bypassed = bypassed_interface(in); | ||
#endif | ||
|
||
if (bypassed) | ||
return 1; | ||
|
||
return 0; | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ | |
#include "af_client.h" | ||
#include "af_client_fs.h" | ||
#include "cJSON.h" | ||
#include "af_bypass.h" | ||
|
||
MODULE_LICENSE("GPL"); | ||
MODULE_AUTHOR("[email protected]"); | ||
|
@@ -691,8 +692,8 @@ static void dump_flow_info(flow_info_t *flow) | |
} | ||
if (flow->l4_len > 0) | ||
{ | ||
AF_LMT_INFO("src=" NIPQUAD_FMT ",dst=" NIPQUAD_FMT ",sport: %d, dport: %d, data_len: %d\n", | ||
NIPQUAD(flow->src), NIPQUAD(flow->dst), flow->sport, flow->dport, flow->l4_len); | ||
AF_LMT_INFO("src=" NIPQUAD_FMT ",dst=" NIPQUAD_FMT ",sport: %d, dport: %d, data_len: %d, http: %d, https: %d\n", | ||
NIPQUAD(flow->src), NIPQUAD(flow->dst), flow->sport, flow->dport, flow->l4_len, flow->http.match, flow->https.match); | ||
} | ||
|
||
if (flow->l4_protocol == IPPROTO_TCP) | ||
|
@@ -982,12 +983,11 @@ u_int32_t app_filter_hook_bypass_handle(struct sk_buff *skb, struct net_device * | |
|
||
if (0 == af_lan_ip || 0 == af_lan_mask) | ||
return NF_ACCEPT; | ||
if (strstr(dev->name, "docker")) | ||
return NF_ACCEPT; | ||
|
||
memset((char *)&flow, 0x0, sizeof(flow_info_t)); | ||
if (parse_flow_proto(skb, &flow) < 0) | ||
return NF_ACCEPT; | ||
|
||
if (flow.src || flow.dst) { | ||
if (af_lan_ip == flow.src || af_lan_ip == flow.dst){ | ||
return NF_ACCEPT; | ||
|
@@ -1116,6 +1116,8 @@ u_int32_t app_filter_hook_gateway_handle(struct sk_buff *skb, struct net_device | |
return NF_ACCEPT; | ||
} | ||
|
||
if (skb->len < 67 || skb->len > 1200) | ||
return NF_ACCEPT; | ||
if (skb_is_nonlinear(skb)) { | ||
flow.l4_data = read_skb(skb, flow.l4_data - skb->data, flow.l4_len); | ||
if (!flow.l4_data) | ||
|
@@ -1187,6 +1189,8 @@ static u_int32_t app_filter_by_pass_hook(unsigned int hook, | |
return NF_ACCEPT; | ||
if (AF_MODE_GATEWAY == af_work_mode) | ||
return NF_ACCEPT; | ||
if (BYPASS_PACKET()) | ||
return NF_ACCEPT; | ||
return app_filter_hook_bypass_handle(skb, skb->dev); | ||
} | ||
|
||
|