ip_vs.h 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /* IP Virtual Server
  3. * data structure and functionality definitions
  4. */
  5. #ifndef _NET_IP_VS_H
  6. #define _NET_IP_VS_H
  7. #include <linux/ip_vs.h> /* definitions shared with userland */
  8. #include <asm/types.h> /* for __uXX types */
  9. #include <linux/list.h> /* for struct list_head */
  10. #include <linux/spinlock.h> /* for struct rwlock_t */
  11. #include <linux/atomic.h> /* for struct atomic_t */
  12. #include <linux/refcount.h> /* for struct refcount_t */
  13. #include <linux/compiler.h>
  14. #include <linux/timer.h>
  15. #include <linux/bug.h>
  16. #include <net/checksum.h>
  17. #include <linux/netfilter.h> /* for union nf_inet_addr */
  18. #include <linux/ip.h>
  19. #include <linux/ipv6.h> /* for struct ipv6hdr */
  20. #include <net/ipv6.h>
  21. #if IS_ENABLED(CONFIG_IP_VS_IPV6)
  22. #include <linux/netfilter_ipv6/ip6_tables.h>
  23. #endif
  24. #if IS_ENABLED(CONFIG_NF_CONNTRACK)
  25. #include <net/netfilter/nf_conntrack.h>
  26. #endif
  27. #include <net/net_namespace.h> /* Netw namespace */
  28. #define IP_VS_HDR_INVERSE 1
  29. #define IP_VS_HDR_ICMP 2
  30. /* Generic access of ipvs struct */
  31. static inline struct netns_ipvs *net_ipvs(struct net* net)
  32. {
  33. return net->ipvs;
  34. }
  35. /* Connections' size value needed by ip_vs_ctl.c */
  36. extern int ip_vs_conn_tab_size;
  37. struct ip_vs_iphdr {
  38. int hdr_flags; /* ipvs flags */
  39. __u32 off; /* Where IP or IPv4 header starts */
  40. __u32 len; /* IPv4 simply where L4 starts
  41. * IPv6 where L4 Transport Header starts */
  42. __u16 fragoffs; /* IPv6 fragment offset, 0 if first frag (or not frag)*/
  43. __s16 protocol;
  44. __s32 flags;
  45. union nf_inet_addr saddr;
  46. union nf_inet_addr daddr;
  47. };
  48. static inline void *frag_safe_skb_hp(const struct sk_buff *skb, int offset,
  49. int len, void *buffer)
  50. {
  51. return skb_header_pointer(skb, offset, len, buffer);
  52. }
  53. /* This function handles filling *ip_vs_iphdr, both for IPv4 and IPv6.
  54. * IPv6 requires some extra work, as finding proper header position,
  55. * depend on the IPv6 extension headers.
  56. */
  57. static inline int
  58. ip_vs_fill_iph_skb_off(int af, const struct sk_buff *skb, int offset,
  59. int hdr_flags, struct ip_vs_iphdr *iphdr)
  60. {
  61. iphdr->hdr_flags = hdr_flags;
  62. iphdr->off = offset;
  63. #ifdef CONFIG_IP_VS_IPV6
  64. if (af == AF_INET6) {
  65. struct ipv6hdr _iph;
  66. const struct ipv6hdr *iph = skb_header_pointer(
  67. skb, offset, sizeof(_iph), &_iph);
  68. if (!iph)
  69. return 0;
  70. iphdr->saddr.in6 = iph->saddr;
  71. iphdr->daddr.in6 = iph->daddr;
  72. /* ipv6_find_hdr() updates len, flags */
  73. iphdr->len = offset;
  74. iphdr->flags = 0;
  75. iphdr->protocol = ipv6_find_hdr(skb, &iphdr->len, -1,
  76. &iphdr->fragoffs,
  77. &iphdr->flags);
  78. if (iphdr->protocol < 0)
  79. return 0;
  80. } else
  81. #endif
  82. {
  83. struct iphdr _iph;
  84. const struct iphdr *iph = skb_header_pointer(
  85. skb, offset, sizeof(_iph), &_iph);
  86. if (!iph)
  87. return 0;
  88. iphdr->len = offset + iph->ihl * 4;
  89. iphdr->fragoffs = 0;
  90. iphdr->protocol = iph->protocol;
  91. iphdr->saddr.ip = iph->saddr;
  92. iphdr->daddr.ip = iph->daddr;
  93. }
  94. return 1;
  95. }
  96. static inline int
  97. ip_vs_fill_iph_skb_icmp(int af, const struct sk_buff *skb, int offset,
  98. bool inverse, struct ip_vs_iphdr *iphdr)
  99. {
  100. int hdr_flags = IP_VS_HDR_ICMP;
  101. if (inverse)
  102. hdr_flags |= IP_VS_HDR_INVERSE;
  103. return ip_vs_fill_iph_skb_off(af, skb, offset, hdr_flags, iphdr);
  104. }
  105. static inline int
  106. ip_vs_fill_iph_skb(int af, const struct sk_buff *skb, bool inverse,
  107. struct ip_vs_iphdr *iphdr)
  108. {
  109. int hdr_flags = 0;
  110. if (inverse)
  111. hdr_flags |= IP_VS_HDR_INVERSE;
  112. return ip_vs_fill_iph_skb_off(af, skb, skb_network_offset(skb),
  113. hdr_flags, iphdr);
  114. }
  115. static inline bool
  116. ip_vs_iph_inverse(const struct ip_vs_iphdr *iph)
  117. {
  118. return !!(iph->hdr_flags & IP_VS_HDR_INVERSE);
  119. }
  120. static inline bool
  121. ip_vs_iph_icmp(const struct ip_vs_iphdr *iph)
  122. {
  123. return !!(iph->hdr_flags & IP_VS_HDR_ICMP);
  124. }
  125. static inline void ip_vs_addr_copy(int af, union nf_inet_addr *dst,
  126. const union nf_inet_addr *src)
  127. {
  128. #ifdef CONFIG_IP_VS_IPV6
  129. if (af == AF_INET6)
  130. dst->in6 = src->in6;
  131. else
  132. #endif
  133. dst->ip = src->ip;
  134. }
  135. static inline void ip_vs_addr_set(int af, union nf_inet_addr *dst,
  136. const union nf_inet_addr *src)
  137. {
  138. #ifdef CONFIG_IP_VS_IPV6
  139. if (af == AF_INET6) {
  140. dst->in6 = src->in6;
  141. return;
  142. }
  143. #endif
  144. dst->ip = src->ip;
  145. dst->all[1] = 0;
  146. dst->all[2] = 0;
  147. dst->all[3] = 0;
  148. }
  149. static inline int ip_vs_addr_equal(int af, const union nf_inet_addr *a,
  150. const union nf_inet_addr *b)
  151. {
  152. #ifdef CONFIG_IP_VS_IPV6
  153. if (af == AF_INET6)
  154. return ipv6_addr_equal(&a->in6, &b->in6);
  155. #endif
  156. return a->ip == b->ip;
  157. }
  158. #ifdef CONFIG_IP_VS_DEBUG
  159. #include <linux/net.h>
  160. int ip_vs_get_debug_level(void);
  161. static inline const char *ip_vs_dbg_addr(int af, char *buf, size_t buf_len,
  162. const union nf_inet_addr *addr,
  163. int *idx)
  164. {
  165. int len;
  166. #ifdef CONFIG_IP_VS_IPV6
  167. if (af == AF_INET6)
  168. len = snprintf(&buf[*idx], buf_len - *idx, "[%pI6c]",
  169. &addr->in6) + 1;
  170. else
  171. #endif
  172. len = snprintf(&buf[*idx], buf_len - *idx, "%pI4",
  173. &addr->ip) + 1;
  174. *idx += len;
  175. BUG_ON(*idx > buf_len + 1);
  176. return &buf[*idx - len];
  177. }
  178. #define IP_VS_DBG_BUF(level, msg, ...) \
  179. do { \
  180. char ip_vs_dbg_buf[160]; \
  181. int ip_vs_dbg_idx = 0; \
  182. if (level <= ip_vs_get_debug_level()) \
  183. printk(KERN_DEBUG pr_fmt(msg), ##__VA_ARGS__); \
  184. } while (0)
  185. #define IP_VS_ERR_BUF(msg...) \
  186. do { \
  187. char ip_vs_dbg_buf[160]; \
  188. int ip_vs_dbg_idx = 0; \
  189. pr_err(msg); \
  190. } while (0)
  191. /* Only use from within IP_VS_DBG_BUF() or IP_VS_ERR_BUF macros */
  192. #define IP_VS_DBG_ADDR(af, addr) \
  193. ip_vs_dbg_addr(af, ip_vs_dbg_buf, \
  194. sizeof(ip_vs_dbg_buf), addr, \
  195. &ip_vs_dbg_idx)
  196. #define IP_VS_DBG(level, msg, ...) \
  197. do { \
  198. if (level <= ip_vs_get_debug_level()) \
  199. printk(KERN_DEBUG pr_fmt(msg), ##__VA_ARGS__); \
  200. } while (0)
  201. #define IP_VS_DBG_RL(msg, ...) \
  202. do { \
  203. if (net_ratelimit()) \
  204. printk(KERN_DEBUG pr_fmt(msg), ##__VA_ARGS__); \
  205. } while (0)
  206. #define IP_VS_DBG_PKT(level, af, pp, skb, ofs, msg) \
  207. do { \
  208. if (level <= ip_vs_get_debug_level()) \
  209. pp->debug_packet(af, pp, skb, ofs, msg); \
  210. } while (0)
  211. #define IP_VS_DBG_RL_PKT(level, af, pp, skb, ofs, msg) \
  212. do { \
  213. if (level <= ip_vs_get_debug_level() && \
  214. net_ratelimit()) \
  215. pp->debug_packet(af, pp, skb, ofs, msg); \
  216. } while (0)
  217. #else /* NO DEBUGGING at ALL */
  218. #define IP_VS_DBG_BUF(level, msg...) do {} while (0)
  219. #define IP_VS_ERR_BUF(msg...) do {} while (0)
  220. #define IP_VS_DBG(level, msg...) do {} while (0)
  221. #define IP_VS_DBG_RL(msg...) do {} while (0)
  222. #define IP_VS_DBG_PKT(level, af, pp, skb, ofs, msg) do {} while (0)
  223. #define IP_VS_DBG_RL_PKT(level, af, pp, skb, ofs, msg) do {} while (0)
  224. #endif
  225. #define IP_VS_BUG() BUG()
  226. #define IP_VS_ERR_RL(msg, ...) \
  227. do { \
  228. if (net_ratelimit()) \
  229. pr_err(msg, ##__VA_ARGS__); \
  230. } while (0)
  231. #ifdef CONFIG_IP_VS_DEBUG
  232. #define EnterFunction(level) \
  233. do { \
  234. if (level <= ip_vs_get_debug_level()) \
  235. printk(KERN_DEBUG \
  236. pr_fmt("Enter: %s, %s line %i\n"), \
  237. __func__, __FILE__, __LINE__); \
  238. } while (0)
  239. #define LeaveFunction(level) \
  240. do { \
  241. if (level <= ip_vs_get_debug_level()) \
  242. printk(KERN_DEBUG \
  243. pr_fmt("Leave: %s, %s line %i\n"), \
  244. __func__, __FILE__, __LINE__); \
  245. } while (0)
  246. #else
  247. #define EnterFunction(level) do {} while (0)
  248. #define LeaveFunction(level) do {} while (0)
  249. #endif
  250. /* The port number of FTP service (in network order). */
  251. #define FTPPORT cpu_to_be16(21)
  252. #define FTPDATA cpu_to_be16(20)
  253. /* TCP State Values */
  254. enum {
  255. IP_VS_TCP_S_NONE = 0,
  256. IP_VS_TCP_S_ESTABLISHED,
  257. IP_VS_TCP_S_SYN_SENT,
  258. IP_VS_TCP_S_SYN_RECV,
  259. IP_VS_TCP_S_FIN_WAIT,
  260. IP_VS_TCP_S_TIME_WAIT,
  261. IP_VS_TCP_S_CLOSE,
  262. IP_VS_TCP_S_CLOSE_WAIT,
  263. IP_VS_TCP_S_LAST_ACK,
  264. IP_VS_TCP_S_LISTEN,
  265. IP_VS_TCP_S_SYNACK,
  266. IP_VS_TCP_S_LAST
  267. };
  268. /* UDP State Values */
  269. enum {
  270. IP_VS_UDP_S_NORMAL,
  271. IP_VS_UDP_S_LAST,
  272. };
  273. /* ICMP State Values */
  274. enum {
  275. IP_VS_ICMP_S_NORMAL,
  276. IP_VS_ICMP_S_LAST,
  277. };
  278. /* SCTP State Values */
  279. enum ip_vs_sctp_states {
  280. IP_VS_SCTP_S_NONE,
  281. IP_VS_SCTP_S_INIT1,
  282. IP_VS_SCTP_S_INIT,
  283. IP_VS_SCTP_S_COOKIE_SENT,
  284. IP_VS_SCTP_S_COOKIE_REPLIED,
  285. IP_VS_SCTP_S_COOKIE_WAIT,
  286. IP_VS_SCTP_S_COOKIE,
  287. IP_VS_SCTP_S_COOKIE_ECHOED,
  288. IP_VS_SCTP_S_ESTABLISHED,
  289. IP_VS_SCTP_S_SHUTDOWN_SENT,
  290. IP_VS_SCTP_S_SHUTDOWN_RECEIVED,
  291. IP_VS_SCTP_S_SHUTDOWN_ACK_SENT,
  292. IP_VS_SCTP_S_REJECTED,
  293. IP_VS_SCTP_S_CLOSED,
  294. IP_VS_SCTP_S_LAST
  295. };
  296. /* Delta sequence info structure
  297. * Each ip_vs_conn has 2 (output AND input seq. changes).
  298. * Only used in the VS/NAT.
  299. */
  300. struct ip_vs_seq {
  301. __u32 init_seq; /* Add delta from this seq */
  302. __u32 delta; /* Delta in sequence numbers */
  303. __u32 previous_delta; /* Delta in sequence numbers
  304. * before last resized pkt */
  305. };
  306. /* counters per cpu */
  307. struct ip_vs_counters {
  308. __u64 conns; /* connections scheduled */
  309. __u64 inpkts; /* incoming packets */
  310. __u64 outpkts; /* outgoing packets */
  311. __u64 inbytes; /* incoming bytes */
  312. __u64 outbytes; /* outgoing bytes */
  313. };
  314. /* Stats per cpu */
  315. struct ip_vs_cpu_stats {
  316. struct ip_vs_counters cnt;
  317. struct u64_stats_sync syncp;
  318. };
  319. /* IPVS statistics objects */
  320. struct ip_vs_estimator {
  321. struct list_head list;
  322. u64 last_inbytes;
  323. u64 last_outbytes;
  324. u64 last_conns;
  325. u64 last_inpkts;
  326. u64 last_outpkts;
  327. u64 cps;
  328. u64 inpps;
  329. u64 outpps;
  330. u64 inbps;
  331. u64 outbps;
  332. };
  333. /*
  334. * IPVS statistics object, 64-bit kernel version of struct ip_vs_stats_user
  335. */
  336. struct ip_vs_kstats {
  337. u64 conns; /* connections scheduled */
  338. u64 inpkts; /* incoming packets */
  339. u64 outpkts; /* outgoing packets */
  340. u64 inbytes; /* incoming bytes */
  341. u64 outbytes; /* outgoing bytes */
  342. u64 cps; /* current connection rate */
  343. u64 inpps; /* current in packet rate */
  344. u64 outpps; /* current out packet rate */
  345. u64 inbps; /* current in byte rate */
  346. u64 outbps; /* current out byte rate */
  347. };
  348. struct ip_vs_stats {
  349. struct ip_vs_kstats kstats; /* kernel statistics */
  350. struct ip_vs_estimator est; /* estimator */
  351. struct ip_vs_cpu_stats __percpu *cpustats; /* per cpu counters */
  352. spinlock_t lock; /* spin lock */
  353. struct ip_vs_kstats kstats0; /* reset values */
  354. };
  355. struct dst_entry;
  356. struct iphdr;
  357. struct ip_vs_conn;
  358. struct ip_vs_app;
  359. struct sk_buff;
  360. struct ip_vs_proto_data;
  361. struct ip_vs_protocol {
  362. struct ip_vs_protocol *next;
  363. char *name;
  364. u16 protocol;
  365. u16 num_states;
  366. int dont_defrag;
  367. void (*init)(struct ip_vs_protocol *pp);
  368. void (*exit)(struct ip_vs_protocol *pp);
  369. int (*init_netns)(struct netns_ipvs *ipvs, struct ip_vs_proto_data *pd);
  370. void (*exit_netns)(struct netns_ipvs *ipvs, struct ip_vs_proto_data *pd);
  371. int (*conn_schedule)(struct netns_ipvs *ipvs,
  372. int af, struct sk_buff *skb,
  373. struct ip_vs_proto_data *pd,
  374. int *verdict, struct ip_vs_conn **cpp,
  375. struct ip_vs_iphdr *iph);
  376. struct ip_vs_conn *
  377. (*conn_in_get)(struct netns_ipvs *ipvs,
  378. int af,
  379. const struct sk_buff *skb,
  380. const struct ip_vs_iphdr *iph);
  381. struct ip_vs_conn *
  382. (*conn_out_get)(struct netns_ipvs *ipvs,
  383. int af,
  384. const struct sk_buff *skb,
  385. const struct ip_vs_iphdr *iph);
  386. int (*snat_handler)(struct sk_buff *skb, struct ip_vs_protocol *pp,
  387. struct ip_vs_conn *cp, struct ip_vs_iphdr *iph);
  388. int (*dnat_handler)(struct sk_buff *skb, struct ip_vs_protocol *pp,
  389. struct ip_vs_conn *cp, struct ip_vs_iphdr *iph);
  390. int (*csum_check)(int af, struct sk_buff *skb,
  391. struct ip_vs_protocol *pp);
  392. const char *(*state_name)(int state);
  393. void (*state_transition)(struct ip_vs_conn *cp, int direction,
  394. const struct sk_buff *skb,
  395. struct ip_vs_proto_data *pd);
  396. int (*register_app)(struct netns_ipvs *ipvs, struct ip_vs_app *inc);
  397. void (*unregister_app)(struct netns_ipvs *ipvs, struct ip_vs_app *inc);
  398. int (*app_conn_bind)(struct ip_vs_conn *cp);
  399. void (*debug_packet)(int af, struct ip_vs_protocol *pp,
  400. const struct sk_buff *skb,
  401. int offset,
  402. const char *msg);
  403. void (*timeout_change)(struct ip_vs_proto_data *pd, int flags);
  404. };
  405. /* protocol data per netns */
  406. struct ip_vs_proto_data {
  407. struct ip_vs_proto_data *next;
  408. struct ip_vs_protocol *pp;
  409. int *timeout_table; /* protocol timeout table */
  410. atomic_t appcnt; /* counter of proto app incs. */
  411. struct tcp_states_t *tcp_state_table;
  412. };
  413. struct ip_vs_protocol *ip_vs_proto_get(unsigned short proto);
  414. struct ip_vs_proto_data *ip_vs_proto_data_get(struct netns_ipvs *ipvs,
  415. unsigned short proto);
  416. struct ip_vs_conn_param {
  417. struct netns_ipvs *ipvs;
  418. const union nf_inet_addr *caddr;
  419. const union nf_inet_addr *vaddr;
  420. __be16 cport;
  421. __be16 vport;
  422. __u16 protocol;
  423. u16 af;
  424. const struct ip_vs_pe *pe;
  425. char *pe_data;
  426. __u8 pe_data_len;
  427. };
  428. /* IP_VS structure allocated for each dynamically scheduled connection */
  429. struct ip_vs_conn {
  430. struct hlist_node c_list; /* hashed list heads */
  431. /* Protocol, addresses and port numbers */
  432. __be16 cport;
  433. __be16 dport;
  434. __be16 vport;
  435. u16 af; /* address family */
  436. union nf_inet_addr caddr; /* client address */
  437. union nf_inet_addr vaddr; /* virtual address */
  438. union nf_inet_addr daddr; /* destination address */
  439. volatile __u32 flags; /* status flags */
  440. __u16 protocol; /* Which protocol (TCP/UDP) */
  441. __u16 daf; /* Address family of the dest */
  442. struct netns_ipvs *ipvs;
  443. /* counter and timer */
  444. refcount_t refcnt; /* reference count */
  445. struct timer_list timer; /* Expiration timer */
  446. volatile unsigned long timeout; /* timeout */
  447. /* Flags and state transition */
  448. spinlock_t lock; /* lock for state transition */
  449. volatile __u16 state; /* state info */
  450. volatile __u16 old_state; /* old state, to be used for
  451. * state transition triggerd
  452. * synchronization
  453. */
  454. __u32 fwmark; /* Fire wall mark from skb */
  455. unsigned long sync_endtime; /* jiffies + sent_retries */
  456. /* Control members */
  457. struct ip_vs_conn *control; /* Master control connection */
  458. atomic_t n_control; /* Number of controlled ones */
  459. struct ip_vs_dest *dest; /* real server */
  460. atomic_t in_pkts; /* incoming packet counter */
  461. /* Packet transmitter for different forwarding methods. If it
  462. * mangles the packet, it must return NF_DROP or better NF_STOLEN,
  463. * otherwise this must be changed to a sk_buff **.
  464. * NF_ACCEPT can be returned when destination is local.
  465. */
  466. int (*packet_xmit)(struct sk_buff *skb, struct ip_vs_conn *cp,
  467. struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
  468. /* Note: we can group the following members into a structure,
  469. * in order to save more space, and the following members are
  470. * only used in VS/NAT anyway
  471. */
  472. struct ip_vs_app *app; /* bound ip_vs_app object */
  473. void *app_data; /* Application private data */
  474. struct ip_vs_seq in_seq; /* incoming seq. struct */
  475. struct ip_vs_seq out_seq; /* outgoing seq. struct */
  476. const struct ip_vs_pe *pe;
  477. char *pe_data;
  478. __u8 pe_data_len;
  479. struct rcu_head rcu_head;
  480. };
  481. /* Extended internal versions of struct ip_vs_service_user and ip_vs_dest_user
  482. * for IPv6 support.
  483. *
  484. * We need these to conveniently pass around service and destination
  485. * options, but unfortunately, we also need to keep the old definitions to
  486. * maintain userspace backwards compatibility for the setsockopt interface.
  487. */
  488. struct ip_vs_service_user_kern {
  489. /* virtual service addresses */
  490. u16 af;
  491. u16 protocol;
  492. union nf_inet_addr addr; /* virtual ip address */
  493. __be16 port;
  494. u32 fwmark; /* firwall mark of service */
  495. /* virtual service options */
  496. char *sched_name;
  497. char *pe_name;
  498. unsigned int flags; /* virtual service flags */
  499. unsigned int timeout; /* persistent timeout in sec */
  500. __be32 netmask; /* persistent netmask or plen */
  501. };
  502. struct ip_vs_dest_user_kern {
  503. /* destination server address */
  504. union nf_inet_addr addr;
  505. __be16 port;
  506. /* real server options */
  507. unsigned int conn_flags; /* connection flags */
  508. int weight; /* destination weight */
  509. /* thresholds for active connections */
  510. u32 u_threshold; /* upper threshold */
  511. u32 l_threshold; /* lower threshold */
  512. /* Address family of addr */
  513. u16 af;
  514. };
  515. /*
  516. * The information about the virtual service offered to the net and the
  517. * forwarding entries.
  518. */
  519. struct ip_vs_service {
  520. struct hlist_node s_list; /* for normal service table */
  521. struct hlist_node f_list; /* for fwmark-based service table */
  522. atomic_t refcnt; /* reference counter */
  523. u16 af; /* address family */
  524. __u16 protocol; /* which protocol (TCP/UDP) */
  525. union nf_inet_addr addr; /* IP address for virtual service */
  526. __be16 port; /* port number for the service */
  527. __u32 fwmark; /* firewall mark of the service */
  528. unsigned int flags; /* service status flags */
  529. unsigned int timeout; /* persistent timeout in ticks */
  530. __be32 netmask; /* grouping granularity, mask/plen */
  531. struct netns_ipvs *ipvs;
  532. struct list_head destinations; /* real server d-linked list */
  533. __u32 num_dests; /* number of servers */
  534. struct ip_vs_stats stats; /* statistics for the service */
  535. /* for scheduling */
  536. struct ip_vs_scheduler __rcu *scheduler; /* bound scheduler object */
  537. spinlock_t sched_lock; /* lock sched_data */
  538. void *sched_data; /* scheduler application data */
  539. /* alternate persistence engine */
  540. struct ip_vs_pe __rcu *pe;
  541. int conntrack_afmask;
  542. struct rcu_head rcu_head;
  543. };
  544. /* Information for cached dst */
  545. struct ip_vs_dest_dst {
  546. struct dst_entry *dst_cache; /* destination cache entry */
  547. u32 dst_cookie;
  548. union nf_inet_addr dst_saddr;
  549. struct rcu_head rcu_head;
  550. };
  551. /* The real server destination forwarding entry with ip address, port number,
  552. * and so on.
  553. */
  554. struct ip_vs_dest {
  555. struct list_head n_list; /* for the dests in the service */
  556. struct hlist_node d_list; /* for table with all the dests */
  557. u16 af; /* address family */
  558. __be16 port; /* port number of the server */
  559. union nf_inet_addr addr; /* IP address of the server */
  560. volatile unsigned int flags; /* dest status flags */
  561. atomic_t conn_flags; /* flags to copy to conn */
  562. atomic_t weight; /* server weight */
  563. atomic_t last_weight; /* server latest weight */
  564. refcount_t refcnt; /* reference counter */
  565. struct ip_vs_stats stats; /* statistics */
  566. unsigned long idle_start; /* start time, jiffies */
  567. /* connection counters and thresholds */
  568. atomic_t activeconns; /* active connections */
  569. atomic_t inactconns; /* inactive connections */
  570. atomic_t persistconns; /* persistent connections */
  571. __u32 u_threshold; /* upper threshold */
  572. __u32 l_threshold; /* lower threshold */
  573. /* for destination cache */
  574. spinlock_t dst_lock; /* lock of dst_cache */
  575. struct ip_vs_dest_dst __rcu *dest_dst; /* cached dst info */
  576. /* for virtual service */
  577. struct ip_vs_service __rcu *svc; /* service it belongs to */
  578. __u16 protocol; /* which protocol (TCP/UDP) */
  579. __be16 vport; /* virtual port number */
  580. union nf_inet_addr vaddr; /* virtual IP address */
  581. __u32 vfwmark; /* firewall mark of service */
  582. struct list_head t_list; /* in dest_trash */
  583. unsigned int in_rs_table:1; /* we are in rs_table */
  584. };
  585. /* The scheduler object */
  586. struct ip_vs_scheduler {
  587. struct list_head n_list; /* d-linked list head */
  588. char *name; /* scheduler name */
  589. atomic_t refcnt; /* reference counter */
  590. struct module *module; /* THIS_MODULE/NULL */
  591. /* scheduler initializing service */
  592. int (*init_service)(struct ip_vs_service *svc);
  593. /* scheduling service finish */
  594. void (*done_service)(struct ip_vs_service *svc);
  595. /* dest is linked */
  596. int (*add_dest)(struct ip_vs_service *svc, struct ip_vs_dest *dest);
  597. /* dest is unlinked */
  598. int (*del_dest)(struct ip_vs_service *svc, struct ip_vs_dest *dest);
  599. /* dest is updated */
  600. int (*upd_dest)(struct ip_vs_service *svc, struct ip_vs_dest *dest);
  601. /* selecting a server from the given service */
  602. struct ip_vs_dest* (*schedule)(struct ip_vs_service *svc,
  603. const struct sk_buff *skb,
  604. struct ip_vs_iphdr *iph);
  605. };
  606. /* The persistence engine object */
  607. struct ip_vs_pe {
  608. struct list_head n_list; /* d-linked list head */
  609. char *name; /* scheduler name */
  610. atomic_t refcnt; /* reference counter */
  611. struct module *module; /* THIS_MODULE/NULL */
  612. /* get the connection template, if any */
  613. int (*fill_param)(struct ip_vs_conn_param *p, struct sk_buff *skb);
  614. bool (*ct_match)(const struct ip_vs_conn_param *p,
  615. struct ip_vs_conn *ct);
  616. u32 (*hashkey_raw)(const struct ip_vs_conn_param *p, u32 initval,
  617. bool inverse);
  618. int (*show_pe_data)(const struct ip_vs_conn *cp, char *buf);
  619. /* create connections for real-server outgoing packets */
  620. struct ip_vs_conn* (*conn_out)(struct ip_vs_service *svc,
  621. struct ip_vs_dest *dest,
  622. struct sk_buff *skb,
  623. const struct ip_vs_iphdr *iph,
  624. __be16 dport, __be16 cport);
  625. };
  626. /* The application module object (a.k.a. app incarnation) */
  627. struct ip_vs_app {
  628. struct list_head a_list; /* member in app list */
  629. int type; /* IP_VS_APP_TYPE_xxx */
  630. char *name; /* application module name */
  631. __u16 protocol;
  632. struct module *module; /* THIS_MODULE/NULL */
  633. struct list_head incs_list; /* list of incarnations */
  634. /* members for application incarnations */
  635. struct list_head p_list; /* member in proto app list */
  636. struct ip_vs_app *app; /* its real application */
  637. __be16 port; /* port number in net order */
  638. atomic_t usecnt; /* usage counter */
  639. struct rcu_head rcu_head;
  640. /* output hook: Process packet in inout direction, diff set for TCP.
  641. * Return: 0=Error, 1=Payload Not Mangled/Mangled but checksum is ok,
  642. * 2=Mangled but checksum was not updated
  643. */
  644. int (*pkt_out)(struct ip_vs_app *, struct ip_vs_conn *,
  645. struct sk_buff *, int *diff, struct ip_vs_iphdr *ipvsh);
  646. /* input hook: Process packet in outin direction, diff set for TCP.
  647. * Return: 0=Error, 1=Payload Not Mangled/Mangled but checksum is ok,
  648. * 2=Mangled but checksum was not updated
  649. */
  650. int (*pkt_in)(struct ip_vs_app *, struct ip_vs_conn *,
  651. struct sk_buff *, int *diff, struct ip_vs_iphdr *ipvsh);
  652. /* ip_vs_app initializer */
  653. int (*init_conn)(struct ip_vs_app *, struct ip_vs_conn *);
  654. /* ip_vs_app finish */
  655. int (*done_conn)(struct ip_vs_app *, struct ip_vs_conn *);
  656. /* not used now */
  657. int (*bind_conn)(struct ip_vs_app *, struct ip_vs_conn *,
  658. struct ip_vs_protocol *);
  659. void (*unbind_conn)(struct ip_vs_app *, struct ip_vs_conn *);
  660. int * timeout_table;
  661. int * timeouts;
  662. int timeouts_size;
  663. int (*conn_schedule)(struct sk_buff *skb, struct ip_vs_app *app,
  664. int *verdict, struct ip_vs_conn **cpp);
  665. struct ip_vs_conn *
  666. (*conn_in_get)(const struct sk_buff *skb, struct ip_vs_app *app,
  667. const struct iphdr *iph, int inverse);
  668. struct ip_vs_conn *
  669. (*conn_out_get)(const struct sk_buff *skb, struct ip_vs_app *app,
  670. const struct iphdr *iph, int inverse);
  671. int (*state_transition)(struct ip_vs_conn *cp, int direction,
  672. const struct sk_buff *skb,
  673. struct ip_vs_app *app);
  674. void (*timeout_change)(struct ip_vs_app *app, int flags);
  675. };
  676. struct ipvs_master_sync_state {
  677. struct list_head sync_queue;
  678. struct ip_vs_sync_buff *sync_buff;
  679. unsigned long sync_queue_len;
  680. unsigned int sync_queue_delay;
  681. struct task_struct *master_thread;
  682. struct delayed_work master_wakeup_work;
  683. struct netns_ipvs *ipvs;
  684. };
  685. /* How much time to keep dests in trash */
  686. #define IP_VS_DEST_TRASH_PERIOD (120 * HZ)
  687. struct ipvs_sync_daemon_cfg {
  688. union nf_inet_addr mcast_group;
  689. int syncid;
  690. u16 sync_maxlen;
  691. u16 mcast_port;
  692. u8 mcast_af;
  693. u8 mcast_ttl;
  694. /* multicast interface name */
  695. char mcast_ifn[IP_VS_IFNAME_MAXLEN];
  696. };
  697. /* IPVS in network namespace */
  698. struct netns_ipvs {
  699. int gen; /* Generation */
  700. int enable; /* enable like nf_hooks do */
  701. /* Hash table: for real service lookups */
  702. #define IP_VS_RTAB_BITS 4
  703. #define IP_VS_RTAB_SIZE (1 << IP_VS_RTAB_BITS)
  704. #define IP_VS_RTAB_MASK (IP_VS_RTAB_SIZE - 1)
  705. struct hlist_head rs_table[IP_VS_RTAB_SIZE];
  706. /* ip_vs_app */
  707. struct list_head app_list;
  708. /* ip_vs_proto */
  709. #define IP_VS_PROTO_TAB_SIZE 32 /* must be power of 2 */
  710. struct ip_vs_proto_data *proto_data_table[IP_VS_PROTO_TAB_SIZE];
  711. /* ip_vs_proto_tcp */
  712. #ifdef CONFIG_IP_VS_PROTO_TCP
  713. #define TCP_APP_TAB_BITS 4
  714. #define TCP_APP_TAB_SIZE (1 << TCP_APP_TAB_BITS)
  715. #define TCP_APP_TAB_MASK (TCP_APP_TAB_SIZE - 1)
  716. struct list_head tcp_apps[TCP_APP_TAB_SIZE];
  717. #endif
  718. /* ip_vs_proto_udp */
  719. #ifdef CONFIG_IP_VS_PROTO_UDP
  720. #define UDP_APP_TAB_BITS 4
  721. #define UDP_APP_TAB_SIZE (1 << UDP_APP_TAB_BITS)
  722. #define UDP_APP_TAB_MASK (UDP_APP_TAB_SIZE - 1)
  723. struct list_head udp_apps[UDP_APP_TAB_SIZE];
  724. #endif
  725. /* ip_vs_proto_sctp */
  726. #ifdef CONFIG_IP_VS_PROTO_SCTP
  727. #define SCTP_APP_TAB_BITS 4
  728. #define SCTP_APP_TAB_SIZE (1 << SCTP_APP_TAB_BITS)
  729. #define SCTP_APP_TAB_MASK (SCTP_APP_TAB_SIZE - 1)
  730. /* Hash table for SCTP application incarnations */
  731. struct list_head sctp_apps[SCTP_APP_TAB_SIZE];
  732. #endif
  733. /* ip_vs_conn */
  734. atomic_t conn_count; /* connection counter */
  735. /* ip_vs_ctl */
  736. struct ip_vs_stats tot_stats; /* Statistics & est. */
  737. int num_services; /* no of virtual services */
  738. /* Trash for destinations */
  739. struct list_head dest_trash;
  740. spinlock_t dest_trash_lock;
  741. struct timer_list dest_trash_timer; /* expiration timer */
  742. /* Service counters */
  743. atomic_t ftpsvc_counter;
  744. atomic_t nullsvc_counter;
  745. atomic_t conn_out_counter;
  746. #ifdef CONFIG_SYSCTL
  747. /* 1/rate drop and drop-entry variables */
  748. struct delayed_work defense_work; /* Work handler */
  749. int drop_rate;
  750. int drop_counter;
  751. atomic_t dropentry;
  752. /* locks in ctl.c */
  753. spinlock_t dropentry_lock; /* drop entry handling */
  754. spinlock_t droppacket_lock; /* drop packet handling */
  755. spinlock_t securetcp_lock; /* state and timeout tables */
  756. /* sys-ctl struct */
  757. struct ctl_table_header *sysctl_hdr;
  758. struct ctl_table *sysctl_tbl;
  759. #endif
  760. /* sysctl variables */
  761. int sysctl_amemthresh;
  762. int sysctl_am_droprate;
  763. int sysctl_drop_entry;
  764. int sysctl_drop_packet;
  765. int sysctl_secure_tcp;
  766. #ifdef CONFIG_IP_VS_NFCT
  767. int sysctl_conntrack;
  768. #endif
  769. int sysctl_snat_reroute;
  770. int sysctl_sync_ver;
  771. int sysctl_sync_ports;
  772. int sysctl_sync_persist_mode;
  773. unsigned long sysctl_sync_qlen_max;
  774. int sysctl_sync_sock_size;
  775. int sysctl_cache_bypass;
  776. int sysctl_expire_nodest_conn;
  777. int sysctl_sloppy_tcp;
  778. int sysctl_sloppy_sctp;
  779. int sysctl_expire_quiescent_template;
  780. int sysctl_sync_threshold[2];
  781. unsigned int sysctl_sync_refresh_period;
  782. int sysctl_sync_retries;
  783. int sysctl_nat_icmp_send;
  784. int sysctl_pmtu_disc;
  785. int sysctl_backup_only;
  786. int sysctl_conn_reuse_mode;
  787. int sysctl_schedule_icmp;
  788. int sysctl_ignore_tunneled;
  789. /* ip_vs_lblc */
  790. int sysctl_lblc_expiration;
  791. struct ctl_table_header *lblc_ctl_header;
  792. struct ctl_table *lblc_ctl_table;
  793. /* ip_vs_lblcr */
  794. int sysctl_lblcr_expiration;
  795. struct ctl_table_header *lblcr_ctl_header;
  796. struct ctl_table *lblcr_ctl_table;
  797. /* ip_vs_est */
  798. struct list_head est_list; /* estimator list */
  799. spinlock_t est_lock;
  800. struct timer_list est_timer; /* Estimation timer */
  801. /* ip_vs_sync */
  802. spinlock_t sync_lock;
  803. struct ipvs_master_sync_state *ms;
  804. spinlock_t sync_buff_lock;
  805. struct task_struct **backup_threads;
  806. int threads_mask;
  807. volatile int sync_state;
  808. struct mutex sync_mutex;
  809. struct ipvs_sync_daemon_cfg mcfg; /* Master Configuration */
  810. struct ipvs_sync_daemon_cfg bcfg; /* Backup Configuration */
  811. /* net name space ptr */
  812. struct net *net; /* Needed by timer routines */
  813. /* Number of heterogeneous destinations, needed becaus heterogeneous
  814. * are not supported when synchronization is enabled.
  815. */
  816. unsigned int mixed_address_family_dests;
  817. };
  818. #define DEFAULT_SYNC_THRESHOLD 3
  819. #define DEFAULT_SYNC_PERIOD 50
  820. #define DEFAULT_SYNC_VER 1
  821. #define DEFAULT_SLOPPY_TCP 0
  822. #define DEFAULT_SLOPPY_SCTP 0
  823. #define DEFAULT_SYNC_REFRESH_PERIOD (0U * HZ)
  824. #define DEFAULT_SYNC_RETRIES 0
  825. #define IPVS_SYNC_WAKEUP_RATE 8
  826. #define IPVS_SYNC_QLEN_MAX (IPVS_SYNC_WAKEUP_RATE * 4)
  827. #define IPVS_SYNC_SEND_DELAY (HZ / 50)
  828. #define IPVS_SYNC_CHECK_PERIOD HZ
  829. #define IPVS_SYNC_FLUSH_TIME (HZ * 2)
  830. #define IPVS_SYNC_PORTS_MAX (1 << 6)
  831. #ifdef CONFIG_SYSCTL
  832. static inline int sysctl_sync_threshold(struct netns_ipvs *ipvs)
  833. {
  834. return ipvs->sysctl_sync_threshold[0];
  835. }
  836. static inline int sysctl_sync_period(struct netns_ipvs *ipvs)
  837. {
  838. return READ_ONCE(ipvs->sysctl_sync_threshold[1]);
  839. }
  840. static inline unsigned int sysctl_sync_refresh_period(struct netns_ipvs *ipvs)
  841. {
  842. return READ_ONCE(ipvs->sysctl_sync_refresh_period);
  843. }
  844. static inline int sysctl_sync_retries(struct netns_ipvs *ipvs)
  845. {
  846. return ipvs->sysctl_sync_retries;
  847. }
  848. static inline int sysctl_sync_ver(struct netns_ipvs *ipvs)
  849. {
  850. return ipvs->sysctl_sync_ver;
  851. }
  852. static inline int sysctl_sloppy_tcp(struct netns_ipvs *ipvs)
  853. {
  854. return ipvs->sysctl_sloppy_tcp;
  855. }
  856. static inline int sysctl_sloppy_sctp(struct netns_ipvs *ipvs)
  857. {
  858. return ipvs->sysctl_sloppy_sctp;
  859. }
  860. static inline int sysctl_sync_ports(struct netns_ipvs *ipvs)
  861. {
  862. return READ_ONCE(ipvs->sysctl_sync_ports);
  863. }
  864. static inline int sysctl_sync_persist_mode(struct netns_ipvs *ipvs)
  865. {
  866. return ipvs->sysctl_sync_persist_mode;
  867. }
  868. static inline unsigned long sysctl_sync_qlen_max(struct netns_ipvs *ipvs)
  869. {
  870. return ipvs->sysctl_sync_qlen_max;
  871. }
  872. static inline int sysctl_sync_sock_size(struct netns_ipvs *ipvs)
  873. {
  874. return ipvs->sysctl_sync_sock_size;
  875. }
  876. static inline int sysctl_pmtu_disc(struct netns_ipvs *ipvs)
  877. {
  878. return ipvs->sysctl_pmtu_disc;
  879. }
  880. static inline int sysctl_backup_only(struct netns_ipvs *ipvs)
  881. {
  882. return ipvs->sync_state & IP_VS_STATE_BACKUP &&
  883. ipvs->sysctl_backup_only;
  884. }
  885. static inline int sysctl_conn_reuse_mode(struct netns_ipvs *ipvs)
  886. {
  887. return ipvs->sysctl_conn_reuse_mode;
  888. }
  889. static inline int sysctl_schedule_icmp(struct netns_ipvs *ipvs)
  890. {
  891. return ipvs->sysctl_schedule_icmp;
  892. }
  893. static inline int sysctl_ignore_tunneled(struct netns_ipvs *ipvs)
  894. {
  895. return ipvs->sysctl_ignore_tunneled;
  896. }
  897. static inline int sysctl_cache_bypass(struct netns_ipvs *ipvs)
  898. {
  899. return ipvs->sysctl_cache_bypass;
  900. }
  901. #else
  902. static inline int sysctl_sync_threshold(struct netns_ipvs *ipvs)
  903. {
  904. return DEFAULT_SYNC_THRESHOLD;
  905. }
  906. static inline int sysctl_sync_period(struct netns_ipvs *ipvs)
  907. {
  908. return DEFAULT_SYNC_PERIOD;
  909. }
  910. static inline unsigned int sysctl_sync_refresh_period(struct netns_ipvs *ipvs)
  911. {
  912. return DEFAULT_SYNC_REFRESH_PERIOD;
  913. }
  914. static inline int sysctl_sync_retries(struct netns_ipvs *ipvs)
  915. {
  916. return DEFAULT_SYNC_RETRIES & 3;
  917. }
  918. static inline int sysctl_sync_ver(struct netns_ipvs *ipvs)
  919. {
  920. return DEFAULT_SYNC_VER;
  921. }
  922. static inline int sysctl_sloppy_tcp(struct netns_ipvs *ipvs)
  923. {
  924. return DEFAULT_SLOPPY_TCP;
  925. }
  926. static inline int sysctl_sloppy_sctp(struct netns_ipvs *ipvs)
  927. {
  928. return DEFAULT_SLOPPY_SCTP;
  929. }
  930. static inline int sysctl_sync_ports(struct netns_ipvs *ipvs)
  931. {
  932. return 1;
  933. }
  934. static inline int sysctl_sync_persist_mode(struct netns_ipvs *ipvs)
  935. {
  936. return 0;
  937. }
  938. static inline unsigned long sysctl_sync_qlen_max(struct netns_ipvs *ipvs)
  939. {
  940. return IPVS_SYNC_QLEN_MAX;
  941. }
  942. static inline int sysctl_sync_sock_size(struct netns_ipvs *ipvs)
  943. {
  944. return 0;
  945. }
  946. static inline int sysctl_pmtu_disc(struct netns_ipvs *ipvs)
  947. {
  948. return 1;
  949. }
  950. static inline int sysctl_backup_only(struct netns_ipvs *ipvs)
  951. {
  952. return 0;
  953. }
  954. static inline int sysctl_conn_reuse_mode(struct netns_ipvs *ipvs)
  955. {
  956. return 1;
  957. }
  958. static inline int sysctl_schedule_icmp(struct netns_ipvs *ipvs)
  959. {
  960. return 0;
  961. }
  962. static inline int sysctl_ignore_tunneled(struct netns_ipvs *ipvs)
  963. {
  964. return 0;
  965. }
  966. static inline int sysctl_cache_bypass(struct netns_ipvs *ipvs)
  967. {
  968. return 0;
  969. }
  970. #endif
  971. /* IPVS core functions
  972. * (from ip_vs_core.c)
  973. */
  974. const char *ip_vs_proto_name(unsigned int proto);
  975. void ip_vs_init_hash_table(struct list_head *table, int rows);
  976. struct ip_vs_conn *ip_vs_new_conn_out(struct ip_vs_service *svc,
  977. struct ip_vs_dest *dest,
  978. struct sk_buff *skb,
  979. const struct ip_vs_iphdr *iph,
  980. __be16 dport,
  981. __be16 cport);
  982. #define IP_VS_INIT_HASH_TABLE(t) ip_vs_init_hash_table((t), ARRAY_SIZE((t)))
  983. #define IP_VS_APP_TYPE_FTP 1
  984. /* ip_vs_conn handling functions
  985. * (from ip_vs_conn.c)
  986. */
  987. enum {
  988. IP_VS_DIR_INPUT = 0,
  989. IP_VS_DIR_OUTPUT,
  990. IP_VS_DIR_INPUT_ONLY,
  991. IP_VS_DIR_LAST,
  992. };
  993. static inline void ip_vs_conn_fill_param(struct netns_ipvs *ipvs, int af, int protocol,
  994. const union nf_inet_addr *caddr,
  995. __be16 cport,
  996. const union nf_inet_addr *vaddr,
  997. __be16 vport,
  998. struct ip_vs_conn_param *p)
  999. {
  1000. p->ipvs = ipvs;
  1001. p->af = af;
  1002. p->protocol = protocol;
  1003. p->caddr = caddr;
  1004. p->cport = cport;
  1005. p->vaddr = vaddr;
  1006. p->vport = vport;
  1007. p->pe = NULL;
  1008. p->pe_data = NULL;
  1009. }
  1010. struct ip_vs_conn *ip_vs_conn_in_get(const struct ip_vs_conn_param *p);
  1011. struct ip_vs_conn *ip_vs_ct_in_get(const struct ip_vs_conn_param *p);
  1012. struct ip_vs_conn * ip_vs_conn_in_get_proto(struct netns_ipvs *ipvs, int af,
  1013. const struct sk_buff *skb,
  1014. const struct ip_vs_iphdr *iph);
  1015. struct ip_vs_conn *ip_vs_conn_out_get(const struct ip_vs_conn_param *p);
  1016. struct ip_vs_conn * ip_vs_conn_out_get_proto(struct netns_ipvs *ipvs, int af,
  1017. const struct sk_buff *skb,
  1018. const struct ip_vs_iphdr *iph);
  1019. /* Get reference to gain full access to conn.
  1020. * By default, RCU read-side critical sections have access only to
  1021. * conn fields and its PE data, see ip_vs_conn_rcu_free() for reference.
  1022. */
  1023. static inline bool __ip_vs_conn_get(struct ip_vs_conn *cp)
  1024. {
  1025. return refcount_inc_not_zero(&cp->refcnt);
  1026. }
  1027. /* put back the conn without restarting its timer */
  1028. static inline void __ip_vs_conn_put(struct ip_vs_conn *cp)
  1029. {
  1030. smp_mb__before_atomic();
  1031. refcount_dec(&cp->refcnt);
  1032. }
  1033. void ip_vs_conn_put(struct ip_vs_conn *cp);
  1034. void ip_vs_conn_fill_cport(struct ip_vs_conn *cp, __be16 cport);
  1035. struct ip_vs_conn *ip_vs_conn_new(const struct ip_vs_conn_param *p, int dest_af,
  1036. const union nf_inet_addr *daddr,
  1037. __be16 dport, unsigned int flags,
  1038. struct ip_vs_dest *dest, __u32 fwmark);
  1039. void ip_vs_conn_expire_now(struct ip_vs_conn *cp);
  1040. const char *ip_vs_state_name(__u16 proto, int state);
  1041. void ip_vs_tcp_conn_listen(struct ip_vs_conn *cp);
  1042. int ip_vs_check_template(struct ip_vs_conn *ct, struct ip_vs_dest *cdest);
  1043. void ip_vs_random_dropentry(struct netns_ipvs *ipvs);
  1044. int ip_vs_conn_init(void);
  1045. void ip_vs_conn_cleanup(void);
  1046. static inline void ip_vs_control_del(struct ip_vs_conn *cp)
  1047. {
  1048. struct ip_vs_conn *ctl_cp = cp->control;
  1049. if (!ctl_cp) {
  1050. IP_VS_ERR_BUF("request control DEL for uncontrolled: "
  1051. "%s:%d to %s:%d\n",
  1052. IP_VS_DBG_ADDR(cp->af, &cp->caddr),
  1053. ntohs(cp->cport),
  1054. IP_VS_DBG_ADDR(cp->af, &cp->vaddr),
  1055. ntohs(cp->vport));
  1056. return;
  1057. }
  1058. IP_VS_DBG_BUF(7, "DELeting control for: "
  1059. "cp.dst=%s:%d ctl_cp.dst=%s:%d\n",
  1060. IP_VS_DBG_ADDR(cp->af, &cp->caddr),
  1061. ntohs(cp->cport),
  1062. IP_VS_DBG_ADDR(cp->af, &ctl_cp->caddr),
  1063. ntohs(ctl_cp->cport));
  1064. cp->control = NULL;
  1065. if (atomic_read(&ctl_cp->n_control) == 0) {
  1066. IP_VS_ERR_BUF("BUG control DEL with n=0 : "
  1067. "%s:%d to %s:%d\n",
  1068. IP_VS_DBG_ADDR(cp->af, &cp->caddr),
  1069. ntohs(cp->cport),
  1070. IP_VS_DBG_ADDR(cp->af, &cp->vaddr),
  1071. ntohs(cp->vport));
  1072. return;
  1073. }
  1074. atomic_dec(&ctl_cp->n_control);
  1075. }
  1076. static inline void
  1077. ip_vs_control_add(struct ip_vs_conn *cp, struct ip_vs_conn *ctl_cp)
  1078. {
  1079. if (cp->control) {
  1080. IP_VS_ERR_BUF("request control ADD for already controlled: "
  1081. "%s:%d to %s:%d\n",
  1082. IP_VS_DBG_ADDR(cp->af, &cp->caddr),
  1083. ntohs(cp->cport),
  1084. IP_VS_DBG_ADDR(cp->af, &cp->vaddr),
  1085. ntohs(cp->vport));
  1086. ip_vs_control_del(cp);
  1087. }
  1088. IP_VS_DBG_BUF(7, "ADDing control for: "
  1089. "cp.dst=%s:%d ctl_cp.dst=%s:%d\n",
  1090. IP_VS_DBG_ADDR(cp->af, &cp->caddr),
  1091. ntohs(cp->cport),
  1092. IP_VS_DBG_ADDR(cp->af, &ctl_cp->caddr),
  1093. ntohs(ctl_cp->cport));
  1094. cp->control = ctl_cp;
  1095. atomic_inc(&ctl_cp->n_control);
  1096. }
  1097. /* IPVS netns init & cleanup functions */
  1098. int ip_vs_estimator_net_init(struct netns_ipvs *ipvs);
  1099. int ip_vs_control_net_init(struct netns_ipvs *ipvs);
  1100. int ip_vs_protocol_net_init(struct netns_ipvs *ipvs);
  1101. int ip_vs_app_net_init(struct netns_ipvs *ipvs);
  1102. int ip_vs_conn_net_init(struct netns_ipvs *ipvs);
  1103. int ip_vs_sync_net_init(struct netns_ipvs *ipvs);
  1104. void ip_vs_conn_net_cleanup(struct netns_ipvs *ipvs);
  1105. void ip_vs_app_net_cleanup(struct netns_ipvs *ipvs);
  1106. void ip_vs_protocol_net_cleanup(struct netns_ipvs *ipvs);
  1107. void ip_vs_control_net_cleanup(struct netns_ipvs *ipvs);
  1108. void ip_vs_estimator_net_cleanup(struct netns_ipvs *ipvs);
  1109. void ip_vs_sync_net_cleanup(struct netns_ipvs *ipvs);
  1110. void ip_vs_service_net_cleanup(struct netns_ipvs *ipvs);
  1111. /* IPVS application functions
  1112. * (from ip_vs_app.c)
  1113. */
  1114. #define IP_VS_APP_MAX_PORTS 8
  1115. struct ip_vs_app *register_ip_vs_app(struct netns_ipvs *ipvs, struct ip_vs_app *app);
  1116. void unregister_ip_vs_app(struct netns_ipvs *ipvs, struct ip_vs_app *app);
  1117. int ip_vs_bind_app(struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
  1118. void ip_vs_unbind_app(struct ip_vs_conn *cp);
  1119. int register_ip_vs_app_inc(struct netns_ipvs *ipvs, struct ip_vs_app *app, __u16 proto,
  1120. __u16 port);
  1121. int ip_vs_app_inc_get(struct ip_vs_app *inc);
  1122. void ip_vs_app_inc_put(struct ip_vs_app *inc);
  1123. int ip_vs_app_pkt_out(struct ip_vs_conn *, struct sk_buff *skb,
  1124. struct ip_vs_iphdr *ipvsh);
  1125. int ip_vs_app_pkt_in(struct ip_vs_conn *, struct sk_buff *skb,
  1126. struct ip_vs_iphdr *ipvsh);
  1127. int register_ip_vs_pe(struct ip_vs_pe *pe);
  1128. int unregister_ip_vs_pe(struct ip_vs_pe *pe);
  1129. struct ip_vs_pe *ip_vs_pe_getbyname(const char *name);
  1130. struct ip_vs_pe *__ip_vs_pe_getbyname(const char *pe_name);
  1131. /* Use a #define to avoid all of module.h just for these trivial ops */
  1132. #define ip_vs_pe_get(pe) \
  1133. if (pe && pe->module) \
  1134. __module_get(pe->module);
  1135. #define ip_vs_pe_put(pe) \
  1136. if (pe && pe->module) \
  1137. module_put(pe->module);
  1138. /* IPVS protocol functions (from ip_vs_proto.c) */
  1139. int ip_vs_protocol_init(void);
  1140. void ip_vs_protocol_cleanup(void);
  1141. void ip_vs_protocol_timeout_change(struct netns_ipvs *ipvs, int flags);
  1142. int *ip_vs_create_timeout_table(int *table, int size);
  1143. void ip_vs_tcpudp_debug_packet(int af, struct ip_vs_protocol *pp,
  1144. const struct sk_buff *skb, int offset,
  1145. const char *msg);
  1146. extern struct ip_vs_protocol ip_vs_protocol_tcp;
  1147. extern struct ip_vs_protocol ip_vs_protocol_udp;
  1148. extern struct ip_vs_protocol ip_vs_protocol_icmp;
  1149. extern struct ip_vs_protocol ip_vs_protocol_esp;
  1150. extern struct ip_vs_protocol ip_vs_protocol_ah;
  1151. extern struct ip_vs_protocol ip_vs_protocol_sctp;
  1152. /* Registering/unregistering scheduler functions
  1153. * (from ip_vs_sched.c)
  1154. */
  1155. int register_ip_vs_scheduler(struct ip_vs_scheduler *scheduler);
  1156. int unregister_ip_vs_scheduler(struct ip_vs_scheduler *scheduler);
  1157. int ip_vs_bind_scheduler(struct ip_vs_service *svc,
  1158. struct ip_vs_scheduler *scheduler);
  1159. void ip_vs_unbind_scheduler(struct ip_vs_service *svc,
  1160. struct ip_vs_scheduler *sched);
  1161. struct ip_vs_scheduler *ip_vs_scheduler_get(const char *sched_name);
  1162. void ip_vs_scheduler_put(struct ip_vs_scheduler *scheduler);
  1163. struct ip_vs_conn *
  1164. ip_vs_schedule(struct ip_vs_service *svc, struct sk_buff *skb,
  1165. struct ip_vs_proto_data *pd, int *ignored,
  1166. struct ip_vs_iphdr *iph);
  1167. int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
  1168. struct ip_vs_proto_data *pd, struct ip_vs_iphdr *iph);
  1169. void ip_vs_scheduler_err(struct ip_vs_service *svc, const char *msg);
  1170. /* IPVS control data and functions (from ip_vs_ctl.c) */
  1171. extern struct ip_vs_stats ip_vs_stats;
  1172. extern int sysctl_ip_vs_sync_ver;
  1173. struct ip_vs_service *
  1174. ip_vs_service_find(struct netns_ipvs *ipvs, int af, __u32 fwmark, __u16 protocol,
  1175. const union nf_inet_addr *vaddr, __be16 vport);
  1176. bool ip_vs_has_real_service(struct netns_ipvs *ipvs, int af, __u16 protocol,
  1177. const union nf_inet_addr *daddr, __be16 dport);
  1178. struct ip_vs_dest *
  1179. ip_vs_find_real_service(struct netns_ipvs *ipvs, int af, __u16 protocol,
  1180. const union nf_inet_addr *daddr, __be16 dport);
  1181. int ip_vs_use_count_inc(void);
  1182. void ip_vs_use_count_dec(void);
  1183. int ip_vs_register_nl_ioctl(void);
  1184. void ip_vs_unregister_nl_ioctl(void);
  1185. int ip_vs_control_init(void);
  1186. void ip_vs_control_cleanup(void);
  1187. struct ip_vs_dest *
  1188. ip_vs_find_dest(struct netns_ipvs *ipvs, int svc_af, int dest_af,
  1189. const union nf_inet_addr *daddr, __be16 dport,
  1190. const union nf_inet_addr *vaddr, __be16 vport,
  1191. __u16 protocol, __u32 fwmark, __u32 flags);
  1192. void ip_vs_try_bind_dest(struct ip_vs_conn *cp);
  1193. static inline void ip_vs_dest_hold(struct ip_vs_dest *dest)
  1194. {
  1195. refcount_inc(&dest->refcnt);
  1196. }
  1197. static inline void ip_vs_dest_put(struct ip_vs_dest *dest)
  1198. {
  1199. smp_mb__before_atomic();
  1200. refcount_dec(&dest->refcnt);
  1201. }
  1202. static inline void ip_vs_dest_put_and_free(struct ip_vs_dest *dest)
  1203. {
  1204. if (refcount_dec_and_test(&dest->refcnt))
  1205. kfree(dest);
  1206. }
  1207. /* IPVS sync daemon data and function prototypes
  1208. * (from ip_vs_sync.c)
  1209. */
  1210. int start_sync_thread(struct netns_ipvs *ipvs, struct ipvs_sync_daemon_cfg *cfg,
  1211. int state);
  1212. int stop_sync_thread(struct netns_ipvs *ipvs, int state);
  1213. void ip_vs_sync_conn(struct netns_ipvs *ipvs, struct ip_vs_conn *cp, int pkts);
  1214. /* IPVS rate estimator prototypes (from ip_vs_est.c) */
  1215. void ip_vs_start_estimator(struct netns_ipvs *ipvs, struct ip_vs_stats *stats);
  1216. void ip_vs_stop_estimator(struct netns_ipvs *ipvs, struct ip_vs_stats *stats);
  1217. void ip_vs_zero_estimator(struct ip_vs_stats *stats);
  1218. void ip_vs_read_estimator(struct ip_vs_kstats *dst, struct ip_vs_stats *stats);
  1219. /* Various IPVS packet transmitters (from ip_vs_xmit.c) */
  1220. int ip_vs_null_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
  1221. struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
  1222. int ip_vs_bypass_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
  1223. struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
  1224. int ip_vs_nat_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
  1225. struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
  1226. int ip_vs_tunnel_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
  1227. struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
  1228. int ip_vs_dr_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
  1229. struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
  1230. int ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
  1231. struct ip_vs_protocol *pp, int offset,
  1232. unsigned int hooknum, struct ip_vs_iphdr *iph);
  1233. void ip_vs_dest_dst_rcu_free(struct rcu_head *head);
  1234. #ifdef CONFIG_IP_VS_IPV6
  1235. int ip_vs_bypass_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
  1236. struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
  1237. int ip_vs_nat_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
  1238. struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
  1239. int ip_vs_tunnel_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
  1240. struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
  1241. int ip_vs_dr_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
  1242. struct ip_vs_protocol *pp, struct ip_vs_iphdr *iph);
  1243. int ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
  1244. struct ip_vs_protocol *pp, int offset,
  1245. unsigned int hooknum, struct ip_vs_iphdr *iph);
  1246. #endif
  1247. #ifdef CONFIG_SYSCTL
  1248. /* This is a simple mechanism to ignore packets when
  1249. * we are loaded. Just set ip_vs_drop_rate to 'n' and
  1250. * we start to drop 1/rate of the packets
  1251. */
  1252. static inline int ip_vs_todrop(struct netns_ipvs *ipvs)
  1253. {
  1254. if (!ipvs->drop_rate)
  1255. return 0;
  1256. if (--ipvs->drop_counter > 0)
  1257. return 0;
  1258. ipvs->drop_counter = ipvs->drop_rate;
  1259. return 1;
  1260. }
  1261. #else
  1262. static inline int ip_vs_todrop(struct netns_ipvs *ipvs) { return 0; }
  1263. #endif
  1264. /* ip_vs_fwd_tag returns the forwarding tag of the connection */
  1265. #define IP_VS_FWD_METHOD(cp) (cp->flags & IP_VS_CONN_F_FWD_MASK)
  1266. static inline char ip_vs_fwd_tag(struct ip_vs_conn *cp)
  1267. {
  1268. char fwd;
  1269. switch (IP_VS_FWD_METHOD(cp)) {
  1270. case IP_VS_CONN_F_MASQ:
  1271. fwd = 'M'; break;
  1272. case IP_VS_CONN_F_LOCALNODE:
  1273. fwd = 'L'; break;
  1274. case IP_VS_CONN_F_TUNNEL:
  1275. fwd = 'T'; break;
  1276. case IP_VS_CONN_F_DROUTE:
  1277. fwd = 'R'; break;
  1278. case IP_VS_CONN_F_BYPASS:
  1279. fwd = 'B'; break;
  1280. default:
  1281. fwd = '?'; break;
  1282. }
  1283. return fwd;
  1284. }
  1285. void ip_vs_nat_icmp(struct sk_buff *skb, struct ip_vs_protocol *pp,
  1286. struct ip_vs_conn *cp, int dir);
  1287. #ifdef CONFIG_IP_VS_IPV6
  1288. void ip_vs_nat_icmp_v6(struct sk_buff *skb, struct ip_vs_protocol *pp,
  1289. struct ip_vs_conn *cp, int dir);
  1290. #endif
  1291. __sum16 ip_vs_checksum_complete(struct sk_buff *skb, int offset);
  1292. static inline __wsum ip_vs_check_diff4(__be32 old, __be32 new, __wsum oldsum)
  1293. {
  1294. __be32 diff[2] = { ~old, new };
  1295. return csum_partial(diff, sizeof(diff), oldsum);
  1296. }
  1297. #ifdef CONFIG_IP_VS_IPV6
  1298. static inline __wsum ip_vs_check_diff16(const __be32 *old, const __be32 *new,
  1299. __wsum oldsum)
  1300. {
  1301. __be32 diff[8] = { ~old[3], ~old[2], ~old[1], ~old[0],
  1302. new[3], new[2], new[1], new[0] };
  1303. return csum_partial(diff, sizeof(diff), oldsum);
  1304. }
  1305. #endif
  1306. static inline __wsum ip_vs_check_diff2(__be16 old, __be16 new, __wsum oldsum)
  1307. {
  1308. __be16 diff[2] = { ~old, new };
  1309. return csum_partial(diff, sizeof(diff), oldsum);
  1310. }
  1311. /* Forget current conntrack (unconfirmed) and attach notrack entry */
  1312. static inline void ip_vs_notrack(struct sk_buff *skb)
  1313. {
  1314. #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
  1315. enum ip_conntrack_info ctinfo;
  1316. struct nf_conn *ct = nf_ct_get(skb, &ctinfo);
  1317. if (ct) {
  1318. nf_conntrack_put(&ct->ct_general);
  1319. nf_ct_set(skb, NULL, IP_CT_UNTRACKED);
  1320. }
  1321. #endif
  1322. }
  1323. #ifdef CONFIG_IP_VS_NFCT
  1324. /* Netfilter connection tracking
  1325. * (from ip_vs_nfct.c)
  1326. */
  1327. static inline int ip_vs_conntrack_enabled(struct netns_ipvs *ipvs)
  1328. {
  1329. #ifdef CONFIG_SYSCTL
  1330. return ipvs->sysctl_conntrack;
  1331. #else
  1332. return 0;
  1333. #endif
  1334. }
  1335. void ip_vs_update_conntrack(struct sk_buff *skb, struct ip_vs_conn *cp,
  1336. int outin);
  1337. int ip_vs_confirm_conntrack(struct sk_buff *skb);
  1338. void ip_vs_nfct_expect_related(struct sk_buff *skb, struct nf_conn *ct,
  1339. struct ip_vs_conn *cp, u_int8_t proto,
  1340. const __be16 port, int from_rs);
  1341. void ip_vs_conn_drop_conntrack(struct ip_vs_conn *cp);
  1342. #else
  1343. static inline int ip_vs_conntrack_enabled(struct netns_ipvs *ipvs)
  1344. {
  1345. return 0;
  1346. }
  1347. static inline void ip_vs_update_conntrack(struct sk_buff *skb,
  1348. struct ip_vs_conn *cp, int outin)
  1349. {
  1350. }
  1351. static inline int ip_vs_confirm_conntrack(struct sk_buff *skb)
  1352. {
  1353. return NF_ACCEPT;
  1354. }
  1355. static inline void ip_vs_conn_drop_conntrack(struct ip_vs_conn *cp)
  1356. {
  1357. }
  1358. #endif /* CONFIG_IP_VS_NFCT */
  1359. /* Really using conntrack? */
  1360. static inline bool ip_vs_conn_uses_conntrack(struct ip_vs_conn *cp,
  1361. struct sk_buff *skb)
  1362. {
  1363. #ifdef CONFIG_IP_VS_NFCT
  1364. enum ip_conntrack_info ctinfo;
  1365. struct nf_conn *ct;
  1366. if (!(cp->flags & IP_VS_CONN_F_NFCT))
  1367. return false;
  1368. ct = nf_ct_get(skb, &ctinfo);
  1369. if (ct)
  1370. return true;
  1371. #endif
  1372. return false;
  1373. }
  1374. static inline int ip_vs_register_conntrack(struct ip_vs_service *svc)
  1375. {
  1376. #if IS_ENABLED(CONFIG_NF_CONNTRACK)
  1377. int afmask = (svc->af == AF_INET6) ? 2 : 1;
  1378. int ret = 0;
  1379. if (!(svc->conntrack_afmask & afmask)) {
  1380. ret = nf_ct_netns_get(svc->ipvs->net, svc->af);
  1381. if (ret >= 0)
  1382. svc->conntrack_afmask |= afmask;
  1383. }
  1384. return ret;
  1385. #else
  1386. return 0;
  1387. #endif
  1388. }
  1389. static inline void ip_vs_unregister_conntrack(struct ip_vs_service *svc)
  1390. {
  1391. #if IS_ENABLED(CONFIG_NF_CONNTRACK)
  1392. int afmask = (svc->af == AF_INET6) ? 2 : 1;
  1393. if (svc->conntrack_afmask & afmask) {
  1394. nf_ct_netns_put(svc->ipvs->net, svc->af);
  1395. svc->conntrack_afmask &= ~afmask;
  1396. }
  1397. #endif
  1398. }
  1399. static inline int
  1400. ip_vs_dest_conn_overhead(struct ip_vs_dest *dest)
  1401. {
  1402. /* We think the overhead of processing active connections is 256
  1403. * times higher than that of inactive connections in average. (This
  1404. * 256 times might not be accurate, we will change it later) We
  1405. * use the following formula to estimate the overhead now:
  1406. * dest->activeconns*256 + dest->inactconns
  1407. */
  1408. return (atomic_read(&dest->activeconns) << 8) +
  1409. atomic_read(&dest->inactconns);
  1410. }
  1411. #endif /* _NET_IP_VS_H */