1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (c) 2022 Huawei Device Co., Ltd.
4 *
5 * Description: Definitions for the NewIP Hooks
6 * Register module.
7 *
8 * Author: Yang Yanjun <yangyanjun@huawei.com>
9 *
10 * Data: 2022-09-20
11 */
12 #ifdef CONFIG_NEWIP_HOOKS
13 #define pr_fmt(fmt) KBUILD_MODNAME ": [%s:%d] " fmt, __func__, __LINE__
14
15 #include <linux/module.h>
16 #include <linux/init.h>
17 #include <linux/hck/lite_hck_inet.h>
18 #include <net/ninet_hashtables.h> /* ninet_ehashfn */
19 #include "tcp_nip_parameter.h"
20
21 /* call the newip hook function in sk_ehashfn function (net\ipv4\inet_hashtables.c):
22 */
nip_ninet_ehashfn(const struct sock * sk,u32 * ret)23 void nip_ninet_ehashfn(const struct sock *sk, u32 *ret)
24 {
25 if (!sk || !ret)
26 return;
27
28 *ret = ninet_ehashfn(sock_net(sk), &sk->SK_NIP_RCV_SADDR,
29 sk->sk_num, &sk->SK_NIP_DADDR, sk->sk_dport);
30 }
31
nip_ninet_ehashfn_lhck_register(void)32 void nip_ninet_ehashfn_lhck_register(void)
33 {
34 REGISTER_HCK_LITE_HOOK(nip_ninet_ehashfn_lhck, nip_ninet_ehashfn);
35 }
36
ninet_hooks_init(void)37 int __init ninet_hooks_init(void)
38 {
39 nip_ninet_ehashfn_lhck_register();
40 return 0;
41 }
42
ninet_hooks_exit(void)43 void __exit ninet_hooks_exit(void)
44 {
45 }
46
47 module_init(ninet_hooks_init);
48 module_exit(ninet_hooks_exit);
49
50 #endif /* CONFIG_NEWIP_HOOKS */
51
52