ip_vs.h 34 KB

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