ip_vs.h 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222
  1. /*
  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. /* old ipvsadm versions still include this file directly */
  9. #ifdef __KERNEL__
  10. #include <asm/types.h> /* for __uXX types */
  11. #include <linux/sysctl.h> /* for ctl_path */
  12. #include <linux/list.h> /* for struct list_head */
  13. #include <linux/spinlock.h> /* for struct rwlock_t */
  14. #include <asm/atomic.h> /* for struct atomic_t */
  15. #include <linux/compiler.h>
  16. #include <linux/timer.h>
  17. #include <net/checksum.h>
  18. #include <linux/netfilter.h> /* for union nf_inet_addr */
  19. #include <linux/ip.h>
  20. #include <linux/ipv6.h> /* for struct ipv6hdr */
  21. #include <net/ipv6.h> /* for ipv6_addr_copy */
  22. #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
  23. #include <net/netfilter/nf_conntrack.h>
  24. #endif
  25. #include <net/net_namespace.h> /* Netw namespace */
  26. /*
  27. * Generic access of ipvs struct
  28. */
  29. static inline struct netns_ipvs *net_ipvs(struct net* net)
  30. {
  31. return net->ipvs;
  32. }
  33. /*
  34. * Get net ptr from skb in traffic cases
  35. * use skb_sknet when call is from userland (ioctl or netlink)
  36. */
  37. static inline struct net *skb_net(struct sk_buff *skb)
  38. {
  39. #ifdef CONFIG_NET_NS
  40. #ifdef CONFIG_IP_VS_DEBUG
  41. /*
  42. * This is used for debug only.
  43. * Start with the most likely hit
  44. * End with BUG
  45. */
  46. if (likely(skb->dev && skb->dev->nd_net))
  47. return dev_net(skb->dev);
  48. if (skb_dst(skb)->dev)
  49. return dev_net(skb_dst(skb)->dev);
  50. WARN(skb->sk, "Maybe skb_sknet should be used in %s() at line:%d\n",
  51. __func__, __LINE__);
  52. if (likely(skb->sk && skb->sk->sk_net))
  53. return sock_net(skb->sk);
  54. pr_err("There is no net ptr to find in the skb in %s() line:%d\n",
  55. __func__, __LINE__);
  56. BUG();
  57. #else
  58. return dev_net(skb->dev ? : skb_dst(skb)->dev);
  59. #endif
  60. #else
  61. return &init_net;
  62. #endif
  63. }
  64. static inline struct net *skb_sknet(struct sk_buff *skb)
  65. {
  66. #ifdef CONFIG_NET_NS
  67. #ifdef CONFIG_IP_VS_DEBUG
  68. /* Start with the most likely hit */
  69. if (likely(skb->sk && skb->sk->sk_net))
  70. return sock_net(skb->sk);
  71. WARN(skb->dev, "Maybe skb_net should be used instead in %s() line:%d\n",
  72. __func__, __LINE__);
  73. if (likely(skb->dev && skb->dev->nd_net))
  74. return dev_net(skb->dev);
  75. pr_err("There is no net ptr to find in the skb in %s() line:%d\n",
  76. __func__, __LINE__);
  77. BUG();
  78. #else
  79. return sock_net(skb->sk);
  80. #endif
  81. #else
  82. return &init_net;
  83. #endif
  84. }
  85. /*
  86. * This one needed for single_open_net since net is stored directly in
  87. * private not as a struct i.e. seq_file_net cant be used.
  88. */
  89. static inline struct net *seq_file_single_net(struct seq_file *seq)
  90. {
  91. #ifdef CONFIG_NET_NS
  92. return (struct net *)seq->private;
  93. #else
  94. return &init_net;
  95. #endif
  96. }
  97. /* Connections' size value needed by ip_vs_ctl.c */
  98. extern int ip_vs_conn_tab_size;
  99. struct ip_vs_iphdr {
  100. int len;
  101. __u8 protocol;
  102. union nf_inet_addr saddr;
  103. union nf_inet_addr daddr;
  104. };
  105. static inline void
  106. ip_vs_fill_iphdr(int af, const void *nh, struct ip_vs_iphdr *iphdr)
  107. {
  108. #ifdef CONFIG_IP_VS_IPV6
  109. if (af == AF_INET6) {
  110. const struct ipv6hdr *iph = nh;
  111. iphdr->len = sizeof(struct ipv6hdr);
  112. iphdr->protocol = iph->nexthdr;
  113. ipv6_addr_copy(&iphdr->saddr.in6, &iph->saddr);
  114. ipv6_addr_copy(&iphdr->daddr.in6, &iph->daddr);
  115. } else
  116. #endif
  117. {
  118. const struct iphdr *iph = nh;
  119. iphdr->len = iph->ihl * 4;
  120. iphdr->protocol = iph->protocol;
  121. iphdr->saddr.ip = iph->saddr;
  122. iphdr->daddr.ip = iph->daddr;
  123. }
  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. ipv6_addr_copy(&dst->in6, &src->in6);
  131. else
  132. #endif
  133. dst->ip = src->ip;
  134. }
  135. static inline int ip_vs_addr_equal(int af, const union nf_inet_addr *a,
  136. const union nf_inet_addr *b)
  137. {
  138. #ifdef CONFIG_IP_VS_IPV6
  139. if (af == AF_INET6)
  140. return ipv6_addr_equal(&a->in6, &b->in6);
  141. #endif
  142. return a->ip == b->ip;
  143. }
  144. #ifdef CONFIG_IP_VS_DEBUG
  145. #include <linux/net.h>
  146. extern int ip_vs_get_debug_level(void);
  147. static inline const char *ip_vs_dbg_addr(int af, char *buf, size_t buf_len,
  148. const union nf_inet_addr *addr,
  149. int *idx)
  150. {
  151. int len;
  152. #ifdef CONFIG_IP_VS_IPV6
  153. if (af == AF_INET6)
  154. len = snprintf(&buf[*idx], buf_len - *idx, "[%pI6]",
  155. &addr->in6) + 1;
  156. else
  157. #endif
  158. len = snprintf(&buf[*idx], buf_len - *idx, "%pI4",
  159. &addr->ip) + 1;
  160. *idx += len;
  161. BUG_ON(*idx > buf_len + 1);
  162. return &buf[*idx - len];
  163. }
  164. #define IP_VS_DBG_BUF(level, msg, ...) \
  165. do { \
  166. char ip_vs_dbg_buf[160]; \
  167. int ip_vs_dbg_idx = 0; \
  168. if (level <= ip_vs_get_debug_level()) \
  169. printk(KERN_DEBUG pr_fmt(msg), ##__VA_ARGS__); \
  170. } while (0)
  171. #define IP_VS_ERR_BUF(msg...) \
  172. do { \
  173. char ip_vs_dbg_buf[160]; \
  174. int ip_vs_dbg_idx = 0; \
  175. pr_err(msg); \
  176. } while (0)
  177. /* Only use from within IP_VS_DBG_BUF() or IP_VS_ERR_BUF macros */
  178. #define IP_VS_DBG_ADDR(af, addr) \
  179. ip_vs_dbg_addr(af, ip_vs_dbg_buf, \
  180. sizeof(ip_vs_dbg_buf), addr, \
  181. &ip_vs_dbg_idx)
  182. #define IP_VS_DBG(level, msg, ...) \
  183. do { \
  184. if (level <= ip_vs_get_debug_level()) \
  185. printk(KERN_DEBUG pr_fmt(msg), ##__VA_ARGS__); \
  186. } while (0)
  187. #define IP_VS_DBG_RL(msg, ...) \
  188. do { \
  189. if (net_ratelimit()) \
  190. printk(KERN_DEBUG pr_fmt(msg), ##__VA_ARGS__); \
  191. } while (0)
  192. #define IP_VS_DBG_PKT(level, af, pp, skb, ofs, msg) \
  193. do { \
  194. if (level <= ip_vs_get_debug_level()) \
  195. pp->debug_packet(af, pp, skb, ofs, msg); \
  196. } while (0)
  197. #define IP_VS_DBG_RL_PKT(level, af, pp, skb, ofs, msg) \
  198. do { \
  199. if (level <= ip_vs_get_debug_level() && \
  200. net_ratelimit()) \
  201. pp->debug_packet(af, pp, skb, ofs, msg); \
  202. } while (0)
  203. #else /* NO DEBUGGING at ALL */
  204. #define IP_VS_DBG_BUF(level, msg...) do {} while (0)
  205. #define IP_VS_ERR_BUF(msg...) do {} while (0)
  206. #define IP_VS_DBG(level, msg...) do {} while (0)
  207. #define IP_VS_DBG_RL(msg...) do {} while (0)
  208. #define IP_VS_DBG_PKT(level, af, pp, skb, ofs, msg) do {} while (0)
  209. #define IP_VS_DBG_RL_PKT(level, af, pp, skb, ofs, msg) do {} while (0)
  210. #endif
  211. #define IP_VS_BUG() BUG()
  212. #define IP_VS_ERR_RL(msg, ...) \
  213. do { \
  214. if (net_ratelimit()) \
  215. pr_err(msg, ##__VA_ARGS__); \
  216. } while (0)
  217. #ifdef CONFIG_IP_VS_DEBUG
  218. #define EnterFunction(level) \
  219. do { \
  220. if (level <= ip_vs_get_debug_level()) \
  221. printk(KERN_DEBUG \
  222. pr_fmt("Enter: %s, %s line %i\n"), \
  223. __func__, __FILE__, __LINE__); \
  224. } while (0)
  225. #define LeaveFunction(level) \
  226. do { \
  227. if (level <= ip_vs_get_debug_level()) \
  228. printk(KERN_DEBUG \
  229. pr_fmt("Leave: %s, %s line %i\n"), \
  230. __func__, __FILE__, __LINE__); \
  231. } while (0)
  232. #else
  233. #define EnterFunction(level) do {} while (0)
  234. #define LeaveFunction(level) do {} while (0)
  235. #endif
  236. #define IP_VS_WAIT_WHILE(expr) while (expr) { cpu_relax(); }
  237. /*
  238. * The port number of FTP service (in network order).
  239. */
  240. #define FTPPORT cpu_to_be16(21)
  241. #define FTPDATA cpu_to_be16(20)
  242. /*
  243. * TCP State Values
  244. */
  245. enum {
  246. IP_VS_TCP_S_NONE = 0,
  247. IP_VS_TCP_S_ESTABLISHED,
  248. IP_VS_TCP_S_SYN_SENT,
  249. IP_VS_TCP_S_SYN_RECV,
  250. IP_VS_TCP_S_FIN_WAIT,
  251. IP_VS_TCP_S_TIME_WAIT,
  252. IP_VS_TCP_S_CLOSE,
  253. IP_VS_TCP_S_CLOSE_WAIT,
  254. IP_VS_TCP_S_LAST_ACK,
  255. IP_VS_TCP_S_LISTEN,
  256. IP_VS_TCP_S_SYNACK,
  257. IP_VS_TCP_S_LAST
  258. };
  259. /*
  260. * UDP State Values
  261. */
  262. enum {
  263. IP_VS_UDP_S_NORMAL,
  264. IP_VS_UDP_S_LAST,
  265. };
  266. /*
  267. * ICMP State Values
  268. */
  269. enum {
  270. IP_VS_ICMP_S_NORMAL,
  271. IP_VS_ICMP_S_LAST,
  272. };
  273. /*
  274. * SCTP State Values
  275. */
  276. enum ip_vs_sctp_states {
  277. IP_VS_SCTP_S_NONE,
  278. IP_VS_SCTP_S_INIT_CLI,
  279. IP_VS_SCTP_S_INIT_SER,
  280. IP_VS_SCTP_S_INIT_ACK_CLI,
  281. IP_VS_SCTP_S_INIT_ACK_SER,
  282. IP_VS_SCTP_S_ECHO_CLI,
  283. IP_VS_SCTP_S_ECHO_SER,
  284. IP_VS_SCTP_S_ESTABLISHED,
  285. IP_VS_SCTP_S_SHUT_CLI,
  286. IP_VS_SCTP_S_SHUT_SER,
  287. IP_VS_SCTP_S_SHUT_ACK_CLI,
  288. IP_VS_SCTP_S_SHUT_ACK_SER,
  289. IP_VS_SCTP_S_CLOSED,
  290. IP_VS_SCTP_S_LAST
  291. };
  292. /*
  293. * Delta sequence info structure
  294. * Each ip_vs_conn has 2 (output AND input seq. changes).
  295. * Only used in the VS/NAT.
  296. */
  297. struct ip_vs_seq {
  298. __u32 init_seq; /* Add delta from this seq */
  299. __u32 delta; /* Delta in sequence numbers */
  300. __u32 previous_delta; /* Delta in sequence numbers
  301. before last resized pkt */
  302. };
  303. /*
  304. * counters per cpu
  305. */
  306. struct ip_vs_counters {
  307. __u32 conns; /* connections scheduled */
  308. __u32 inpkts; /* incoming packets */
  309. __u32 outpkts; /* outgoing packets */
  310. __u64 inbytes; /* incoming bytes */
  311. __u64 outbytes; /* outgoing bytes */
  312. };
  313. /*
  314. * Stats per cpu
  315. */
  316. struct ip_vs_cpu_stats {
  317. struct ip_vs_counters ustats;
  318. struct u64_stats_sync syncp;
  319. };
  320. /*
  321. * IPVS statistics objects
  322. */
  323. struct ip_vs_estimator {
  324. struct list_head list;
  325. u64 last_inbytes;
  326. u64 last_outbytes;
  327. u32 last_conns;
  328. u32 last_inpkts;
  329. u32 last_outpkts;
  330. u32 cps;
  331. u32 inpps;
  332. u32 outpps;
  333. u32 inbps;
  334. u32 outbps;
  335. };
  336. struct ip_vs_stats {
  337. struct ip_vs_stats_user ustats; /* statistics */
  338. struct ip_vs_estimator est; /* estimator */
  339. struct ip_vs_cpu_stats *cpustats; /* per cpu counters */
  340. spinlock_t lock; /* spin lock */
  341. };
  342. /*
  343. * Helper Macros for per cpu
  344. * ipvs->tot_stats->ustats.count
  345. */
  346. #define IPVS_STAT_INC(ipvs, count) \
  347. __this_cpu_inc((ipvs)->ustats->count)
  348. #define IPVS_STAT_ADD(ipvs, count, value) \
  349. do {\
  350. write_seqcount_begin(per_cpu_ptr((ipvs)->ustats_seq, \
  351. raw_smp_processor_id())); \
  352. __this_cpu_add((ipvs)->ustats->count, value); \
  353. write_seqcount_end(per_cpu_ptr((ipvs)->ustats_seq, \
  354. raw_smp_processor_id())); \
  355. } while (0)
  356. struct dst_entry;
  357. struct iphdr;
  358. struct ip_vs_conn;
  359. struct ip_vs_app;
  360. struct sk_buff;
  361. struct ip_vs_proto_data;
  362. struct ip_vs_protocol {
  363. struct ip_vs_protocol *next;
  364. char *name;
  365. u16 protocol;
  366. u16 num_states;
  367. int dont_defrag;
  368. void (*init)(struct ip_vs_protocol *pp);
  369. void (*exit)(struct ip_vs_protocol *pp);
  370. void (*init_netns)(struct net *net, struct ip_vs_proto_data *pd);
  371. void (*exit_netns)(struct net *net, struct ip_vs_proto_data *pd);
  372. int (*conn_schedule)(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_conn *
  376. (*conn_in_get)(int af,
  377. const struct sk_buff *skb,
  378. const struct ip_vs_iphdr *iph,
  379. unsigned int proto_off,
  380. int inverse);
  381. struct ip_vs_conn *
  382. (*conn_out_get)(int af,
  383. const struct sk_buff *skb,
  384. const struct ip_vs_iphdr *iph,
  385. unsigned int proto_off,
  386. int inverse);
  387. int (*snat_handler)(struct sk_buff *skb,
  388. struct ip_vs_protocol *pp, struct ip_vs_conn *cp);
  389. int (*dnat_handler)(struct sk_buff *skb,
  390. struct ip_vs_protocol *pp, struct ip_vs_conn *cp);
  391. int (*csum_check)(int af, struct sk_buff *skb,
  392. struct ip_vs_protocol *pp);
  393. const char *(*state_name)(int state);
  394. int (*state_transition)(struct ip_vs_conn *cp, int direction,
  395. const struct sk_buff *skb,
  396. struct ip_vs_proto_data *pd);
  397. int (*register_app)(struct net *net, struct ip_vs_app *inc);
  398. void (*unregister_app)(struct net *net, struct ip_vs_app *inc);
  399. int (*app_conn_bind)(struct ip_vs_conn *cp);
  400. void (*debug_packet)(int af, struct ip_vs_protocol *pp,
  401. const struct sk_buff *skb,
  402. int offset,
  403. const char *msg);
  404. void (*timeout_change)(struct ip_vs_proto_data *pd, int flags);
  405. };
  406. /*
  407. * protocol data per netns
  408. */
  409. struct ip_vs_proto_data {
  410. struct ip_vs_proto_data *next;
  411. struct ip_vs_protocol *pp;
  412. int *timeout_table; /* protocol timeout table */
  413. atomic_t appcnt; /* counter of proto app incs. */
  414. struct tcp_states_t *tcp_state_table;
  415. };
  416. extern struct ip_vs_protocol *ip_vs_proto_get(unsigned short proto);
  417. extern struct ip_vs_proto_data *ip_vs_proto_data_get(struct net *net,
  418. unsigned short proto);
  419. struct ip_vs_conn_param {
  420. const union nf_inet_addr *caddr;
  421. const union nf_inet_addr *vaddr;
  422. __be16 cport;
  423. __be16 vport;
  424. __u16 protocol;
  425. u16 af;
  426. const struct ip_vs_pe *pe;
  427. char *pe_data;
  428. __u8 pe_data_len;
  429. };
  430. /*
  431. * IP_VS structure allocated for each dynamically scheduled connection
  432. */
  433. struct ip_vs_conn {
  434. struct list_head c_list; /* hashed list heads */
  435. /* Protocol, addresses and port numbers */
  436. u16 af; /* address family */
  437. union nf_inet_addr caddr; /* client address */
  438. union nf_inet_addr vaddr; /* virtual address */
  439. union nf_inet_addr daddr; /* destination address */
  440. volatile __u32 flags; /* status flags */
  441. __u32 fwmark; /* Fire wall mark from skb */
  442. __be16 cport;
  443. __be16 vport;
  444. __be16 dport;
  445. __u16 protocol; /* Which protocol (TCP/UDP) */
  446. /* counter and timer */
  447. atomic_t refcnt; /* reference count */
  448. struct timer_list timer; /* Expiration timer */
  449. volatile unsigned long timeout; /* timeout */
  450. /* Flags and state transition */
  451. spinlock_t lock; /* lock for state transition */
  452. volatile __u16 state; /* state info */
  453. volatile __u16 old_state; /* old state, to be used for
  454. * state transition triggerd
  455. * synchronization
  456. */
  457. /* Control members */
  458. struct ip_vs_conn *control; /* Master control connection */
  459. atomic_t n_control; /* Number of controlled ones */
  460. struct ip_vs_dest *dest; /* real server */
  461. atomic_t in_pkts; /* incoming packet counter */
  462. /* packet transmitter for different forwarding methods. If it
  463. mangles the packet, it must return NF_DROP or better NF_STOLEN,
  464. otherwise this must be changed to a sk_buff **.
  465. NF_ACCEPT can be returned when destination is local.
  466. */
  467. int (*packet_xmit)(struct sk_buff *skb, struct ip_vs_conn *cp,
  468. struct ip_vs_protocol *pp);
  469. /* Note: we can group the following members into a structure,
  470. in order to save more space, and the following members are
  471. only used in VS/NAT anyway */
  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. };
  480. /*
  481. * Extended internal versions of struct ip_vs_service_user and
  482. * ip_vs_dest_user 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. u16 port;
  494. u32 fwmark; /* firwall mark of service */
  495. /* virtual service options */
  496. char *sched_name;
  497. char *pe_name;
  498. unsigned flags; /* virtual service flags */
  499. unsigned timeout; /* persistent timeout in sec */
  500. u32 netmask; /* persistent netmask */
  501. };
  502. struct ip_vs_dest_user_kern {
  503. /* destination server address */
  504. union nf_inet_addr addr;
  505. u16 port;
  506. /* real server options */
  507. unsigned 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. };
  513. /*
  514. * The information about the virtual service offered to the net
  515. * and the forwarding entries
  516. */
  517. struct ip_vs_service {
  518. struct list_head s_list; /* for normal service table */
  519. struct list_head f_list; /* for fwmark-based service table */
  520. atomic_t refcnt; /* reference counter */
  521. atomic_t usecnt; /* use counter */
  522. u16 af; /* address family */
  523. __u16 protocol; /* which protocol (TCP/UDP) */
  524. union nf_inet_addr addr; /* IP address for virtual service */
  525. __be16 port; /* port number for the service */
  526. __u32 fwmark; /* firewall mark of the service */
  527. unsigned flags; /* service status flags */
  528. unsigned timeout; /* persistent timeout in ticks */
  529. __be32 netmask; /* grouping granularity */
  530. struct net *net;
  531. struct list_head destinations; /* real server d-linked list */
  532. __u32 num_dests; /* number of servers */
  533. struct ip_vs_stats stats; /* statistics for the service */
  534. struct ip_vs_app *inc; /* bind conns to this app inc */
  535. /* for scheduling */
  536. struct ip_vs_scheduler *scheduler; /* bound scheduler object */
  537. rwlock_t sched_lock; /* lock sched_data */
  538. void *sched_data; /* scheduler application data */
  539. /* alternate persistence engine */
  540. struct ip_vs_pe *pe;
  541. };
  542. /*
  543. * The real server destination forwarding entry
  544. * with ip address, port number, and so on.
  545. */
  546. struct ip_vs_dest {
  547. struct list_head n_list; /* for the dests in the service */
  548. struct list_head d_list; /* for table with all the dests */
  549. u16 af; /* address family */
  550. union nf_inet_addr addr; /* IP address of the server */
  551. __be16 port; /* port number of the server */
  552. volatile unsigned flags; /* dest status flags */
  553. atomic_t conn_flags; /* flags to copy to conn */
  554. atomic_t weight; /* server weight */
  555. atomic_t refcnt; /* reference counter */
  556. struct ip_vs_stats stats; /* statistics */
  557. /* connection counters and thresholds */
  558. atomic_t activeconns; /* active connections */
  559. atomic_t inactconns; /* inactive connections */
  560. atomic_t persistconns; /* persistent connections */
  561. __u32 u_threshold; /* upper threshold */
  562. __u32 l_threshold; /* lower threshold */
  563. /* for destination cache */
  564. spinlock_t dst_lock; /* lock of dst_cache */
  565. struct dst_entry *dst_cache; /* destination cache entry */
  566. u32 dst_rtos; /* RT_TOS(tos) for dst */
  567. u32 dst_cookie;
  568. #ifdef CONFIG_IP_VS_IPV6
  569. struct in6_addr dst_saddr;
  570. #endif
  571. /* for virtual service */
  572. struct ip_vs_service *svc; /* service it belongs to */
  573. __u16 protocol; /* which protocol (TCP/UDP) */
  574. union nf_inet_addr vaddr; /* virtual IP address */
  575. __be16 vport; /* virtual port number */
  576. __u32 vfwmark; /* firewall mark of service */
  577. };
  578. /*
  579. * The scheduler object
  580. */
  581. struct ip_vs_scheduler {
  582. struct list_head n_list; /* d-linked list head */
  583. char *name; /* scheduler name */
  584. atomic_t refcnt; /* reference counter */
  585. struct module *module; /* THIS_MODULE/NULL */
  586. /* scheduler initializing service */
  587. int (*init_service)(struct ip_vs_service *svc);
  588. /* scheduling service finish */
  589. int (*done_service)(struct ip_vs_service *svc);
  590. /* scheduler updating service */
  591. int (*update_service)(struct ip_vs_service *svc);
  592. /* selecting a server from the given service */
  593. struct ip_vs_dest* (*schedule)(struct ip_vs_service *svc,
  594. const struct sk_buff *skb);
  595. };
  596. /* The persistence engine object */
  597. struct ip_vs_pe {
  598. struct list_head n_list; /* d-linked list head */
  599. char *name; /* scheduler name */
  600. atomic_t refcnt; /* reference counter */
  601. struct module *module; /* THIS_MODULE/NULL */
  602. /* get the connection template, if any */
  603. int (*fill_param)(struct ip_vs_conn_param *p, struct sk_buff *skb);
  604. bool (*ct_match)(const struct ip_vs_conn_param *p,
  605. struct ip_vs_conn *ct);
  606. u32 (*hashkey_raw)(const struct ip_vs_conn_param *p, u32 initval,
  607. bool inverse);
  608. int (*show_pe_data)(const struct ip_vs_conn *cp, char *buf);
  609. };
  610. /*
  611. * The application module object (a.k.a. app incarnation)
  612. */
  613. struct ip_vs_app {
  614. struct list_head a_list; /* member in app list */
  615. int type; /* IP_VS_APP_TYPE_xxx */
  616. char *name; /* application module name */
  617. __u16 protocol;
  618. struct module *module; /* THIS_MODULE/NULL */
  619. struct list_head incs_list; /* list of incarnations */
  620. /* members for application incarnations */
  621. struct list_head p_list; /* member in proto app list */
  622. struct ip_vs_app *app; /* its real application */
  623. __be16 port; /* port number in net order */
  624. atomic_t usecnt; /* usage counter */
  625. /*
  626. * output hook: Process packet in inout direction, diff set for TCP.
  627. * Return: 0=Error, 1=Payload Not Mangled/Mangled but checksum is ok,
  628. * 2=Mangled but checksum was not updated
  629. */
  630. int (*pkt_out)(struct ip_vs_app *, struct ip_vs_conn *,
  631. struct sk_buff *, int *diff);
  632. /*
  633. * input hook: Process packet in outin direction, diff set for TCP.
  634. * Return: 0=Error, 1=Payload Not Mangled/Mangled but checksum is ok,
  635. * 2=Mangled but checksum was not updated
  636. */
  637. int (*pkt_in)(struct ip_vs_app *, struct ip_vs_conn *,
  638. struct sk_buff *, int *diff);
  639. /* ip_vs_app initializer */
  640. int (*init_conn)(struct ip_vs_app *, struct ip_vs_conn *);
  641. /* ip_vs_app finish */
  642. int (*done_conn)(struct ip_vs_app *, struct ip_vs_conn *);
  643. /* not used now */
  644. int (*bind_conn)(struct ip_vs_app *, struct ip_vs_conn *,
  645. struct ip_vs_protocol *);
  646. void (*unbind_conn)(struct ip_vs_app *, struct ip_vs_conn *);
  647. int * timeout_table;
  648. int * timeouts;
  649. int timeouts_size;
  650. int (*conn_schedule)(struct sk_buff *skb, struct ip_vs_app *app,
  651. int *verdict, struct ip_vs_conn **cpp);
  652. struct ip_vs_conn *
  653. (*conn_in_get)(const struct sk_buff *skb, struct ip_vs_app *app,
  654. const struct iphdr *iph, unsigned int proto_off,
  655. int inverse);
  656. struct ip_vs_conn *
  657. (*conn_out_get)(const struct sk_buff *skb, struct ip_vs_app *app,
  658. const struct iphdr *iph, unsigned int proto_off,
  659. int inverse);
  660. int (*state_transition)(struct ip_vs_conn *cp, int direction,
  661. const struct sk_buff *skb,
  662. struct ip_vs_app *app);
  663. void (*timeout_change)(struct ip_vs_app *app, int flags);
  664. };
  665. /*
  666. * IPVS core functions
  667. * (from ip_vs_core.c)
  668. */
  669. extern const char *ip_vs_proto_name(unsigned proto);
  670. extern void ip_vs_init_hash_table(struct list_head *table, int rows);
  671. #define IP_VS_INIT_HASH_TABLE(t) ip_vs_init_hash_table((t), ARRAY_SIZE((t)))
  672. #define IP_VS_APP_TYPE_FTP 1
  673. /*
  674. * ip_vs_conn handling functions
  675. * (from ip_vs_conn.c)
  676. */
  677. enum {
  678. IP_VS_DIR_INPUT = 0,
  679. IP_VS_DIR_OUTPUT,
  680. IP_VS_DIR_INPUT_ONLY,
  681. IP_VS_DIR_LAST,
  682. };
  683. static inline void ip_vs_conn_fill_param(int af, int protocol,
  684. const union nf_inet_addr *caddr,
  685. __be16 cport,
  686. const union nf_inet_addr *vaddr,
  687. __be16 vport,
  688. struct ip_vs_conn_param *p)
  689. {
  690. p->af = af;
  691. p->protocol = protocol;
  692. p->caddr = caddr;
  693. p->cport = cport;
  694. p->vaddr = vaddr;
  695. p->vport = vport;
  696. p->pe = NULL;
  697. p->pe_data = NULL;
  698. }
  699. struct ip_vs_conn *ip_vs_conn_in_get(const struct ip_vs_conn_param *p);
  700. struct ip_vs_conn *ip_vs_ct_in_get(const struct ip_vs_conn_param *p);
  701. struct ip_vs_conn * ip_vs_conn_in_get_proto(int af, const struct sk_buff *skb,
  702. const struct ip_vs_iphdr *iph,
  703. unsigned int proto_off,
  704. int inverse);
  705. struct ip_vs_conn *ip_vs_conn_out_get(const struct ip_vs_conn_param *p);
  706. struct ip_vs_conn * ip_vs_conn_out_get_proto(int af, const struct sk_buff *skb,
  707. const struct ip_vs_iphdr *iph,
  708. unsigned int proto_off,
  709. int inverse);
  710. /* put back the conn without restarting its timer */
  711. static inline void __ip_vs_conn_put(struct ip_vs_conn *cp)
  712. {
  713. atomic_dec(&cp->refcnt);
  714. }
  715. extern void ip_vs_conn_put(struct ip_vs_conn *cp);
  716. extern void ip_vs_conn_fill_cport(struct ip_vs_conn *cp, __be16 cport);
  717. struct ip_vs_conn *ip_vs_conn_new(const struct ip_vs_conn_param *p,
  718. const union nf_inet_addr *daddr,
  719. __be16 dport, unsigned flags,
  720. struct ip_vs_dest *dest, __u32 fwmark);
  721. extern void ip_vs_conn_expire_now(struct ip_vs_conn *cp);
  722. extern const char * ip_vs_state_name(__u16 proto, int state);
  723. extern void ip_vs_tcp_conn_listen(struct net *net, struct ip_vs_conn *cp);
  724. extern int ip_vs_check_template(struct ip_vs_conn *ct);
  725. extern void ip_vs_random_dropentry(void);
  726. extern int ip_vs_conn_init(void);
  727. extern void ip_vs_conn_cleanup(void);
  728. static inline void ip_vs_control_del(struct ip_vs_conn *cp)
  729. {
  730. struct ip_vs_conn *ctl_cp = cp->control;
  731. if (!ctl_cp) {
  732. IP_VS_ERR_BUF("request control DEL for uncontrolled: "
  733. "%s:%d to %s:%d\n",
  734. IP_VS_DBG_ADDR(cp->af, &cp->caddr),
  735. ntohs(cp->cport),
  736. IP_VS_DBG_ADDR(cp->af, &cp->vaddr),
  737. ntohs(cp->vport));
  738. return;
  739. }
  740. IP_VS_DBG_BUF(7, "DELeting control for: "
  741. "cp.dst=%s:%d ctl_cp.dst=%s:%d\n",
  742. IP_VS_DBG_ADDR(cp->af, &cp->caddr),
  743. ntohs(cp->cport),
  744. IP_VS_DBG_ADDR(cp->af, &ctl_cp->caddr),
  745. ntohs(ctl_cp->cport));
  746. cp->control = NULL;
  747. if (atomic_read(&ctl_cp->n_control) == 0) {
  748. IP_VS_ERR_BUF("BUG control DEL with n=0 : "
  749. "%s:%d to %s:%d\n",
  750. IP_VS_DBG_ADDR(cp->af, &cp->caddr),
  751. ntohs(cp->cport),
  752. IP_VS_DBG_ADDR(cp->af, &cp->vaddr),
  753. ntohs(cp->vport));
  754. return;
  755. }
  756. atomic_dec(&ctl_cp->n_control);
  757. }
  758. static inline void
  759. ip_vs_control_add(struct ip_vs_conn *cp, struct ip_vs_conn *ctl_cp)
  760. {
  761. if (cp->control) {
  762. IP_VS_ERR_BUF("request control ADD for already controlled: "
  763. "%s:%d to %s:%d\n",
  764. IP_VS_DBG_ADDR(cp->af, &cp->caddr),
  765. ntohs(cp->cport),
  766. IP_VS_DBG_ADDR(cp->af, &cp->vaddr),
  767. ntohs(cp->vport));
  768. ip_vs_control_del(cp);
  769. }
  770. IP_VS_DBG_BUF(7, "ADDing control for: "
  771. "cp.dst=%s:%d ctl_cp.dst=%s:%d\n",
  772. IP_VS_DBG_ADDR(cp->af, &cp->caddr),
  773. ntohs(cp->cport),
  774. IP_VS_DBG_ADDR(cp->af, &ctl_cp->caddr),
  775. ntohs(ctl_cp->cport));
  776. cp->control = ctl_cp;
  777. atomic_inc(&ctl_cp->n_control);
  778. }
  779. /*
  780. * IPVS application functions
  781. * (from ip_vs_app.c)
  782. */
  783. #define IP_VS_APP_MAX_PORTS 8
  784. extern int register_ip_vs_app(struct net *net, struct ip_vs_app *app);
  785. extern void unregister_ip_vs_app(struct net *net, struct ip_vs_app *app);
  786. extern int ip_vs_bind_app(struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
  787. extern void ip_vs_unbind_app(struct ip_vs_conn *cp);
  788. extern int register_ip_vs_app_inc(struct net *net, struct ip_vs_app *app,
  789. __u16 proto, __u16 port);
  790. extern int ip_vs_app_inc_get(struct ip_vs_app *inc);
  791. extern void ip_vs_app_inc_put(struct ip_vs_app *inc);
  792. extern int ip_vs_app_pkt_out(struct ip_vs_conn *, struct sk_buff *skb);
  793. extern int ip_vs_app_pkt_in(struct ip_vs_conn *, struct sk_buff *skb);
  794. extern int ip_vs_app_init(void);
  795. extern void ip_vs_app_cleanup(void);
  796. void ip_vs_bind_pe(struct ip_vs_service *svc, struct ip_vs_pe *pe);
  797. void ip_vs_unbind_pe(struct ip_vs_service *svc);
  798. int register_ip_vs_pe(struct ip_vs_pe *pe);
  799. int unregister_ip_vs_pe(struct ip_vs_pe *pe);
  800. struct ip_vs_pe *ip_vs_pe_getbyname(const char *name);
  801. struct ip_vs_pe *__ip_vs_pe_getbyname(const char *pe_name);
  802. static inline void ip_vs_pe_get(const struct ip_vs_pe *pe)
  803. {
  804. if (pe && pe->module)
  805. __module_get(pe->module);
  806. }
  807. static inline void ip_vs_pe_put(const struct ip_vs_pe *pe)
  808. {
  809. if (pe && pe->module)
  810. module_put(pe->module);
  811. }
  812. /*
  813. * IPVS protocol functions (from ip_vs_proto.c)
  814. */
  815. extern int ip_vs_protocol_init(void);
  816. extern void ip_vs_protocol_cleanup(void);
  817. extern void ip_vs_protocol_timeout_change(struct netns_ipvs *ipvs, int flags);
  818. extern int *ip_vs_create_timeout_table(int *table, int size);
  819. extern int
  820. ip_vs_set_state_timeout(int *table, int num, const char *const *names,
  821. const char *name, int to);
  822. extern void
  823. ip_vs_tcpudp_debug_packet(int af, struct ip_vs_protocol *pp,
  824. const struct sk_buff *skb,
  825. int offset, const char *msg);
  826. extern struct ip_vs_protocol ip_vs_protocol_tcp;
  827. extern struct ip_vs_protocol ip_vs_protocol_udp;
  828. extern struct ip_vs_protocol ip_vs_protocol_icmp;
  829. extern struct ip_vs_protocol ip_vs_protocol_esp;
  830. extern struct ip_vs_protocol ip_vs_protocol_ah;
  831. extern struct ip_vs_protocol ip_vs_protocol_sctp;
  832. /*
  833. * Registering/unregistering scheduler functions
  834. * (from ip_vs_sched.c)
  835. */
  836. extern int register_ip_vs_scheduler(struct ip_vs_scheduler *scheduler);
  837. extern int unregister_ip_vs_scheduler(struct ip_vs_scheduler *scheduler);
  838. extern int ip_vs_bind_scheduler(struct ip_vs_service *svc,
  839. struct ip_vs_scheduler *scheduler);
  840. extern int ip_vs_unbind_scheduler(struct ip_vs_service *svc);
  841. extern struct ip_vs_scheduler *ip_vs_scheduler_get(const char *sched_name);
  842. extern void ip_vs_scheduler_put(struct ip_vs_scheduler *scheduler);
  843. extern struct ip_vs_conn *
  844. ip_vs_schedule(struct ip_vs_service *svc, struct sk_buff *skb,
  845. struct ip_vs_proto_data *pd, int *ignored);
  846. extern int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
  847. struct ip_vs_proto_data *pd);
  848. /*
  849. * IPVS control data and functions (from ip_vs_ctl.c)
  850. */
  851. extern int sysctl_ip_vs_cache_bypass;
  852. extern int sysctl_ip_vs_expire_nodest_conn;
  853. extern int sysctl_ip_vs_expire_quiescent_template;
  854. extern int sysctl_ip_vs_sync_threshold[2];
  855. extern int sysctl_ip_vs_nat_icmp_send;
  856. extern int sysctl_ip_vs_conntrack;
  857. extern int sysctl_ip_vs_snat_reroute;
  858. extern struct ip_vs_stats ip_vs_stats;
  859. extern const struct ctl_path net_vs_ctl_path[];
  860. extern int sysctl_ip_vs_sync_ver;
  861. extern void ip_vs_sync_switch_mode(struct net *net, int mode);
  862. extern struct ip_vs_service *
  863. ip_vs_service_get(struct net *net, int af, __u32 fwmark, __u16 protocol,
  864. const union nf_inet_addr *vaddr, __be16 vport);
  865. static inline void ip_vs_service_put(struct ip_vs_service *svc)
  866. {
  867. atomic_dec(&svc->usecnt);
  868. }
  869. extern struct ip_vs_dest *
  870. ip_vs_lookup_real_service(struct net *net, int af, __u16 protocol,
  871. const union nf_inet_addr *daddr, __be16 dport);
  872. extern int ip_vs_use_count_inc(void);
  873. extern void ip_vs_use_count_dec(void);
  874. extern int ip_vs_control_init(void);
  875. extern void ip_vs_control_cleanup(void);
  876. extern struct ip_vs_dest *
  877. ip_vs_find_dest(struct net *net, int af, const union nf_inet_addr *daddr,
  878. __be16 dport, const union nf_inet_addr *vaddr, __be16 vport,
  879. __u16 protocol, __u32 fwmark);
  880. extern struct ip_vs_dest *ip_vs_try_bind_dest(struct ip_vs_conn *cp);
  881. /*
  882. * IPVS sync daemon data and function prototypes
  883. * (from ip_vs_sync.c)
  884. */
  885. extern int start_sync_thread(struct net *net, int state, char *mcast_ifn,
  886. __u8 syncid);
  887. extern int stop_sync_thread(struct net *net, int state);
  888. extern void ip_vs_sync_conn(struct net *net, struct ip_vs_conn *cp);
  889. extern int ip_vs_sync_init(void);
  890. extern void ip_vs_sync_cleanup(void);
  891. /*
  892. * IPVS rate estimator prototypes (from ip_vs_est.c)
  893. */
  894. extern int ip_vs_estimator_init(void);
  895. extern void ip_vs_estimator_cleanup(void);
  896. extern void ip_vs_new_estimator(struct net *net, struct ip_vs_stats *stats);
  897. extern void ip_vs_kill_estimator(struct net *net, struct ip_vs_stats *stats);
  898. extern void ip_vs_zero_estimator(struct ip_vs_stats *stats);
  899. /*
  900. * Various IPVS packet transmitters (from ip_vs_xmit.c)
  901. */
  902. extern int ip_vs_null_xmit
  903. (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
  904. extern int ip_vs_bypass_xmit
  905. (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
  906. extern int ip_vs_nat_xmit
  907. (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
  908. extern int ip_vs_tunnel_xmit
  909. (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
  910. extern int ip_vs_dr_xmit
  911. (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
  912. extern int ip_vs_icmp_xmit
  913. (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp, int offset);
  914. extern void ip_vs_dst_reset(struct ip_vs_dest *dest);
  915. #ifdef CONFIG_IP_VS_IPV6
  916. extern int ip_vs_bypass_xmit_v6
  917. (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
  918. extern int ip_vs_nat_xmit_v6
  919. (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
  920. extern int ip_vs_tunnel_xmit_v6
  921. (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
  922. extern int ip_vs_dr_xmit_v6
  923. (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
  924. extern int ip_vs_icmp_xmit_v6
  925. (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp,
  926. int offset);
  927. #endif
  928. /*
  929. * This is a simple mechanism to ignore packets when
  930. * we are loaded. Just set ip_vs_drop_rate to 'n' and
  931. * we start to drop 1/rate of the packets
  932. */
  933. extern int ip_vs_drop_rate;
  934. extern int ip_vs_drop_counter;
  935. static __inline__ int ip_vs_todrop(void)
  936. {
  937. if (!ip_vs_drop_rate) return 0;
  938. if (--ip_vs_drop_counter > 0) return 0;
  939. ip_vs_drop_counter = ip_vs_drop_rate;
  940. return 1;
  941. }
  942. /*
  943. * ip_vs_fwd_tag returns the forwarding tag of the connection
  944. */
  945. #define IP_VS_FWD_METHOD(cp) (cp->flags & IP_VS_CONN_F_FWD_MASK)
  946. static inline char ip_vs_fwd_tag(struct ip_vs_conn *cp)
  947. {
  948. char fwd;
  949. switch (IP_VS_FWD_METHOD(cp)) {
  950. case IP_VS_CONN_F_MASQ:
  951. fwd = 'M'; break;
  952. case IP_VS_CONN_F_LOCALNODE:
  953. fwd = 'L'; break;
  954. case IP_VS_CONN_F_TUNNEL:
  955. fwd = 'T'; break;
  956. case IP_VS_CONN_F_DROUTE:
  957. fwd = 'R'; break;
  958. case IP_VS_CONN_F_BYPASS:
  959. fwd = 'B'; break;
  960. default:
  961. fwd = '?'; break;
  962. }
  963. return fwd;
  964. }
  965. extern void ip_vs_nat_icmp(struct sk_buff *skb, struct ip_vs_protocol *pp,
  966. struct ip_vs_conn *cp, int dir);
  967. #ifdef CONFIG_IP_VS_IPV6
  968. extern void ip_vs_nat_icmp_v6(struct sk_buff *skb, struct ip_vs_protocol *pp,
  969. struct ip_vs_conn *cp, int dir);
  970. #endif
  971. extern __sum16 ip_vs_checksum_complete(struct sk_buff *skb, int offset);
  972. static inline __wsum ip_vs_check_diff4(__be32 old, __be32 new, __wsum oldsum)
  973. {
  974. __be32 diff[2] = { ~old, new };
  975. return csum_partial(diff, sizeof(diff), oldsum);
  976. }
  977. #ifdef CONFIG_IP_VS_IPV6
  978. static inline __wsum ip_vs_check_diff16(const __be32 *old, const __be32 *new,
  979. __wsum oldsum)
  980. {
  981. __be32 diff[8] = { ~old[3], ~old[2], ~old[1], ~old[0],
  982. new[3], new[2], new[1], new[0] };
  983. return csum_partial(diff, sizeof(diff), oldsum);
  984. }
  985. #endif
  986. static inline __wsum ip_vs_check_diff2(__be16 old, __be16 new, __wsum oldsum)
  987. {
  988. __be16 diff[2] = { ~old, new };
  989. return csum_partial(diff, sizeof(diff), oldsum);
  990. }
  991. /*
  992. * Forget current conntrack (unconfirmed) and attach notrack entry
  993. */
  994. static inline void ip_vs_notrack(struct sk_buff *skb)
  995. {
  996. #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
  997. enum ip_conntrack_info ctinfo;
  998. struct nf_conn *ct = ct = nf_ct_get(skb, &ctinfo);
  999. if (!ct || !nf_ct_is_untracked(ct)) {
  1000. nf_reset(skb);
  1001. skb->nfct = &nf_ct_untracked_get()->ct_general;
  1002. skb->nfctinfo = IP_CT_NEW;
  1003. nf_conntrack_get(skb->nfct);
  1004. }
  1005. #endif
  1006. }
  1007. #ifdef CONFIG_IP_VS_NFCT
  1008. /*
  1009. * Netfilter connection tracking
  1010. * (from ip_vs_nfct.c)
  1011. */
  1012. static inline int ip_vs_conntrack_enabled(void)
  1013. {
  1014. return sysctl_ip_vs_conntrack;
  1015. }
  1016. extern void ip_vs_update_conntrack(struct sk_buff *skb, struct ip_vs_conn *cp,
  1017. int outin);
  1018. extern int ip_vs_confirm_conntrack(struct sk_buff *skb, struct ip_vs_conn *cp);
  1019. extern void ip_vs_nfct_expect_related(struct sk_buff *skb, struct nf_conn *ct,
  1020. struct ip_vs_conn *cp, u_int8_t proto,
  1021. const __be16 port, int from_rs);
  1022. extern void ip_vs_conn_drop_conntrack(struct ip_vs_conn *cp);
  1023. #else
  1024. static inline int ip_vs_conntrack_enabled(void)
  1025. {
  1026. return 0;
  1027. }
  1028. static inline void ip_vs_update_conntrack(struct sk_buff *skb,
  1029. struct ip_vs_conn *cp, int outin)
  1030. {
  1031. }
  1032. static inline int ip_vs_confirm_conntrack(struct sk_buff *skb,
  1033. struct ip_vs_conn *cp)
  1034. {
  1035. return NF_ACCEPT;
  1036. }
  1037. static inline void ip_vs_conn_drop_conntrack(struct ip_vs_conn *cp)
  1038. {
  1039. }
  1040. /* CONFIG_IP_VS_NFCT */
  1041. #endif
  1042. #endif /* __KERNEL__ */
  1043. #endif /* _NET_IP_VS_H */