Skip to content

Commit 5b810f7

Browse files
author
boyu
committed
support linux 5.0
1 parent 3d1d2fc commit 5b810f7

File tree

4 files changed

+32
-7
lines changed

4 files changed

+32
-7
lines changed

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ get ip vs(fullnat) client addr
44

55
由taobao/toa修改,可作为独立模块编译安装, 支持tcp/udp
66

7-
支持 centos6.6(linux 2.6.32-220) / centos7.2(linux 3.10.0-237.4.5) / ubuntu14.04(linux 3.13.0-77-generic) / ubuntu16.04(linux 4.4.0-64-generic) / centos7.2(linux 4.9.2-1.el7)
7+
支持 centos6.6(linux 2.6.32-220) / centos7.2(linux 3.10.0-237.4.5) / ubuntu14.04(linux 3.13.0-77-generic) / ubuntu16.04(linux 4.4.0-64-generic) / centos7.2(linux 4.9.2-1.el7) / ubuntu19.04 (5.0.0-25-generic)
88

99
对应内核在[github.com/yubo/LVS](https://github.com/yubo/LVS/tree/lvs_v2),兼容[taobao/LVS(lvs_v2)](https://github.com/alibaba/LVS/tree/lvs_v2)
1010

@@ -23,6 +23,8 @@ get ip vs(fullnat) client addr
2323
- [x] Support centos 7.2 rpmbuild
2424
- [x] Support ubuntu 14.04(trusty) dpkg
2525
- [x] Support ubuntu 16.04.2(xenial) dpkg
26+
- [x] Support ubuntu 19.04(disco) dpkg (untested)
27+
- [x] Linux (2.6.32 - 5.0.0)
2628

2729
## Demo
2830

src/ca_conn.c

+10
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,15 @@ ip_vs_ca_conn_unhash(struct ip_vs_ca_conn *cp)
191191
return ret;
192192
}
193193

194+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,15,0)
195+
static void ip_vs_ca_conn_expire(struct timer_list *t)
196+
{
197+
struct ip_vs_ca_conn *cp = from_timer(cp, t, timer);
198+
#else
194199
static void ip_vs_ca_conn_expire(unsigned long data)
195200
{
196201
struct ip_vs_ca_conn *cp = (struct ip_vs_ca_conn *)data;
202+
#endif
197203

198204
/*
199205
* Set proper timeout.
@@ -260,7 +266,11 @@ struct ip_vs_ca_conn *ip_vs_ca_conn_new(int af,
260266

261267
/* now init connection */
262268
IP_VS_CA_DBG("setup_timer, %p\n", &cp->timer);
269+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,15,0)
270+
timer_setup(&cp->timer, ip_vs_ca_conn_expire, 0);
271+
#else
263272
setup_timer(&cp->timer, ip_vs_ca_conn_expire, (unsigned long)cp);
273+
#endif
264274
cp->af = af;
265275
cp->protocol = pp->protocol;
266276
//ip_vs_ca_addr_copy(af, &cp->saddr, saddr);

src/ca_core.c

+15-6
Original file line numberDiff line numberDiff line change
@@ -303,24 +303,25 @@ static void ip_vs_ca_syscall_cleanup(void)
303303

304304
static unsigned int _ip_vs_ca_in_hook(struct sk_buff *skb);
305305

306-
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,10,0)
306+
307+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,12,0)
308+
static unsigned int
309+
ip_vs_ca_in_hook(void *priv, struct sk_buff *skb,
310+
const struct nf_hook_state *state)
311+
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(3,10,0)
307312
static unsigned int
308313
ip_vs_ca_in_hook(const struct nf_hook_ops *ops, struct sk_buff *skb,
309314
const struct net_device *in,
310315
const struct net_device *out,
311316
const void *ignore)
312-
{
313-
return _ip_vs_ca_in_hook(skb);
314-
}
315317
#else
316-
static unsigned int
317318
ip_vs_ca_in_hook(unsigned int hooknum, struct sk_buff *skb,
318319
const struct net_device *in, const struct net_device *out,
319320
int (*okfn) (struct sk_buff *))
321+
#endif
320322
{
321323
return _ip_vs_ca_in_hook(skb);
322324
}
323-
#endif
324325

325326
static unsigned int _ip_vs_ca_in_hook(struct sk_buff *skb)
326327
{
@@ -496,7 +497,11 @@ static int __init ip_vs_ca_init(void)
496497
}
497498
IP_VS_CA_DBG("ip_vs_ca_conn_init done.\n");
498499

500+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,12,0)
501+
ret = nf_register_net_hooks(NULL, ip_vs_ca_ops, ARRAY_SIZE(ip_vs_ca_ops));
502+
#else
499503
ret = nf_register_hooks(ip_vs_ca_ops, ARRAY_SIZE(ip_vs_ca_ops));
504+
#endif
500505
if (ret < 0){
501506
IP_VS_CA_ERR("can't register hooks.\n");
502507
goto cleanup_conn;
@@ -518,7 +523,11 @@ static int __init ip_vs_ca_init(void)
518523

519524
static void __exit ip_vs_ca_exit(void)
520525
{
526+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,12,0)
527+
nf_unregister_net_hooks(NULL, ip_vs_ca_ops, ARRAY_SIZE(ip_vs_ca_ops));
528+
#else
521529
nf_unregister_hooks(ip_vs_ca_ops, ARRAY_SIZE(ip_vs_ca_ops));
530+
#endif
522531
ip_vs_ca_conn_cleanup();
523532
ip_vs_ca_protocol_cleanup();
524533
ip_vs_ca_control_cleanup();

src/utils.c

+4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
#include <linux/syscalls.h>
99
#include "ca.h"
1010

11+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,17,0)
12+
#define sys_close ksys_close
13+
#endif
14+
1115
unsigned long **find_sys_call_table(void) {
1216

1317
unsigned long ptr;

0 commit comments

Comments
 (0)