ip_vs.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747
  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. #ifdef CONFIG_IP_VS_DEBUG
  19. #include <linux/net.h>
  20. extern int ip_vs_get_debug_level(void);
  21. #define IP_VS_DBG(level, msg...) \
  22. do { \
  23. if (level <= ip_vs_get_debug_level()) \
  24. printk(KERN_DEBUG "IPVS: " msg); \
  25. } while (0)
  26. #define IP_VS_DBG_RL(msg...) \
  27. do { \
  28. if (net_ratelimit()) \
  29. printk(KERN_DEBUG "IPVS: " msg); \
  30. } while (0)
  31. #define IP_VS_DBG_PKT(level, pp, skb, ofs, msg) \
  32. do { \
  33. if (level <= ip_vs_get_debug_level()) \
  34. pp->debug_packet(pp, skb, ofs, msg); \
  35. } while (0)
  36. #define IP_VS_DBG_RL_PKT(level, pp, skb, ofs, msg) \
  37. do { \
  38. if (level <= ip_vs_get_debug_level() && \
  39. net_ratelimit()) \
  40. pp->debug_packet(pp, skb, ofs, msg); \
  41. } while (0)
  42. #else /* NO DEBUGGING at ALL */
  43. #define IP_VS_DBG(level, msg...) do {} while (0)
  44. #define IP_VS_DBG_RL(msg...) do {} while (0)
  45. #define IP_VS_DBG_PKT(level, pp, skb, ofs, msg) do {} while (0)
  46. #define IP_VS_DBG_RL_PKT(level, pp, skb, ofs, msg) do {} while (0)
  47. #endif
  48. #define IP_VS_BUG() BUG()
  49. #define IP_VS_ERR(msg...) printk(KERN_ERR "IPVS: " msg)
  50. #define IP_VS_INFO(msg...) printk(KERN_INFO "IPVS: " msg)
  51. #define IP_VS_WARNING(msg...) \
  52. printk(KERN_WARNING "IPVS: " msg)
  53. #define IP_VS_ERR_RL(msg...) \
  54. do { \
  55. if (net_ratelimit()) \
  56. printk(KERN_ERR "IPVS: " msg); \
  57. } while (0)
  58. #ifdef CONFIG_IP_VS_DEBUG
  59. #define EnterFunction(level) \
  60. do { \
  61. if (level <= ip_vs_get_debug_level()) \
  62. printk(KERN_DEBUG "Enter: %s, %s line %i\n", \
  63. __FUNCTION__, __FILE__, __LINE__); \
  64. } while (0)
  65. #define LeaveFunction(level) \
  66. do { \
  67. if (level <= ip_vs_get_debug_level()) \
  68. printk(KERN_DEBUG "Leave: %s, %s line %i\n", \
  69. __FUNCTION__, __FILE__, __LINE__); \
  70. } while (0)
  71. #else
  72. #define EnterFunction(level) do {} while (0)
  73. #define LeaveFunction(level) do {} while (0)
  74. #endif
  75. #define IP_VS_WAIT_WHILE(expr) while (expr) { cpu_relax(); }
  76. /*
  77. * The port number of FTP service (in network order).
  78. */
  79. #define FTPPORT __constant_htons(21)
  80. #define FTPDATA __constant_htons(20)
  81. /*
  82. * TCP State Values
  83. */
  84. enum {
  85. IP_VS_TCP_S_NONE = 0,
  86. IP_VS_TCP_S_ESTABLISHED,
  87. IP_VS_TCP_S_SYN_SENT,
  88. IP_VS_TCP_S_SYN_RECV,
  89. IP_VS_TCP_S_FIN_WAIT,
  90. IP_VS_TCP_S_TIME_WAIT,
  91. IP_VS_TCP_S_CLOSE,
  92. IP_VS_TCP_S_CLOSE_WAIT,
  93. IP_VS_TCP_S_LAST_ACK,
  94. IP_VS_TCP_S_LISTEN,
  95. IP_VS_TCP_S_SYNACK,
  96. IP_VS_TCP_S_LAST
  97. };
  98. /*
  99. * UDP State Values
  100. */
  101. enum {
  102. IP_VS_UDP_S_NORMAL,
  103. IP_VS_UDP_S_LAST,
  104. };
  105. /*
  106. * ICMP State Values
  107. */
  108. enum {
  109. IP_VS_ICMP_S_NORMAL,
  110. IP_VS_ICMP_S_LAST,
  111. };
  112. /*
  113. * Delta sequence info structure
  114. * Each ip_vs_conn has 2 (output AND input seq. changes).
  115. * Only used in the VS/NAT.
  116. */
  117. struct ip_vs_seq {
  118. __u32 init_seq; /* Add delta from this seq */
  119. __u32 delta; /* Delta in sequence numbers */
  120. __u32 previous_delta; /* Delta in sequence numbers
  121. before last resized pkt */
  122. };
  123. /*
  124. * IPVS statistics object
  125. */
  126. struct ip_vs_stats
  127. {
  128. __u32 conns; /* connections scheduled */
  129. __u32 inpkts; /* incoming packets */
  130. __u32 outpkts; /* outgoing packets */
  131. __u64 inbytes; /* incoming bytes */
  132. __u64 outbytes; /* outgoing bytes */
  133. __u32 cps; /* current connection rate */
  134. __u32 inpps; /* current in packet rate */
  135. __u32 outpps; /* current out packet rate */
  136. __u32 inbps; /* current in byte rate */
  137. __u32 outbps; /* current out byte rate */
  138. spinlock_t lock; /* spin lock */
  139. };
  140. struct dst_entry;
  141. struct iphdr;
  142. struct ip_vs_conn;
  143. struct ip_vs_app;
  144. struct sk_buff;
  145. struct ip_vs_protocol {
  146. struct ip_vs_protocol *next;
  147. char *name;
  148. u16 protocol;
  149. u16 num_states;
  150. int dont_defrag;
  151. atomic_t appcnt; /* counter of proto app incs */
  152. int *timeout_table; /* protocol timeout table */
  153. void (*init)(struct ip_vs_protocol *pp);
  154. void (*exit)(struct ip_vs_protocol *pp);
  155. int (*conn_schedule)(struct sk_buff *skb,
  156. struct ip_vs_protocol *pp,
  157. int *verdict, struct ip_vs_conn **cpp);
  158. struct ip_vs_conn *
  159. (*conn_in_get)(const struct sk_buff *skb,
  160. struct ip_vs_protocol *pp,
  161. const struct iphdr *iph,
  162. unsigned int proto_off,
  163. int inverse);
  164. struct ip_vs_conn *
  165. (*conn_out_get)(const struct sk_buff *skb,
  166. struct ip_vs_protocol *pp,
  167. const struct iphdr *iph,
  168. unsigned int proto_off,
  169. int inverse);
  170. int (*snat_handler)(struct sk_buff *skb,
  171. struct ip_vs_protocol *pp, struct ip_vs_conn *cp);
  172. int (*dnat_handler)(struct sk_buff *skb,
  173. struct ip_vs_protocol *pp, struct ip_vs_conn *cp);
  174. int (*csum_check)(struct sk_buff *skb, struct ip_vs_protocol *pp);
  175. const char *(*state_name)(int state);
  176. int (*state_transition)(struct ip_vs_conn *cp, int direction,
  177. const struct sk_buff *skb,
  178. struct ip_vs_protocol *pp);
  179. int (*register_app)(struct ip_vs_app *inc);
  180. void (*unregister_app)(struct ip_vs_app *inc);
  181. int (*app_conn_bind)(struct ip_vs_conn *cp);
  182. void (*debug_packet)(struct ip_vs_protocol *pp,
  183. const struct sk_buff *skb,
  184. int offset,
  185. const char *msg);
  186. void (*timeout_change)(struct ip_vs_protocol *pp, int flags);
  187. int (*set_state_timeout)(struct ip_vs_protocol *pp, char *sname, int to);
  188. };
  189. extern struct ip_vs_protocol * ip_vs_proto_get(unsigned short proto);
  190. /*
  191. * IP_VS structure allocated for each dynamically scheduled connection
  192. */
  193. struct ip_vs_conn {
  194. struct list_head c_list; /* hashed list heads */
  195. /* Protocol, addresses and port numbers */
  196. __be32 caddr; /* client address */
  197. __be32 vaddr; /* virtual address */
  198. __be32 daddr; /* destination address */
  199. __be16 cport;
  200. __be16 vport;
  201. __be16 dport;
  202. __u16 protocol; /* Which protocol (TCP/UDP) */
  203. /* counter and timer */
  204. atomic_t refcnt; /* reference count */
  205. struct timer_list timer; /* Expiration timer */
  206. volatile unsigned long timeout; /* timeout */
  207. /* Flags and state transition */
  208. spinlock_t lock; /* lock for state transition */
  209. volatile __u16 flags; /* status flags */
  210. volatile __u16 state; /* state info */
  211. volatile __u16 old_state; /* old state, to be used for
  212. * state transition triggerd
  213. * synchronization
  214. */
  215. /* Control members */
  216. struct ip_vs_conn *control; /* Master control connection */
  217. atomic_t n_control; /* Number of controlled ones */
  218. struct ip_vs_dest *dest; /* real server */
  219. atomic_t in_pkts; /* incoming packet counter */
  220. /* packet transmitter for different forwarding methods. If it
  221. mangles the packet, it must return NF_DROP or better NF_STOLEN,
  222. otherwise this must be changed to a sk_buff **.
  223. */
  224. int (*packet_xmit)(struct sk_buff *skb, struct ip_vs_conn *cp,
  225. struct ip_vs_protocol *pp);
  226. /* Note: we can group the following members into a structure,
  227. in order to save more space, and the following members are
  228. only used in VS/NAT anyway */
  229. struct ip_vs_app *app; /* bound ip_vs_app object */
  230. void *app_data; /* Application private data */
  231. struct ip_vs_seq in_seq; /* incoming seq. struct */
  232. struct ip_vs_seq out_seq; /* outgoing seq. struct */
  233. };
  234. /*
  235. * The information about the virtual service offered to the net
  236. * and the forwarding entries
  237. */
  238. struct ip_vs_service {
  239. struct list_head s_list; /* for normal service table */
  240. struct list_head f_list; /* for fwmark-based service table */
  241. atomic_t refcnt; /* reference counter */
  242. atomic_t usecnt; /* use counter */
  243. __u16 protocol; /* which protocol (TCP/UDP) */
  244. __be32 addr; /* IP address for virtual service */
  245. __be16 port; /* port number for the service */
  246. __u32 fwmark; /* firewall mark of the service */
  247. unsigned flags; /* service status flags */
  248. unsigned timeout; /* persistent timeout in ticks */
  249. __be32 netmask; /* grouping granularity */
  250. struct list_head destinations; /* real server d-linked list */
  251. __u32 num_dests; /* number of servers */
  252. struct ip_vs_stats stats; /* statistics for the service */
  253. struct ip_vs_app *inc; /* bind conns to this app inc */
  254. /* for scheduling */
  255. struct ip_vs_scheduler *scheduler; /* bound scheduler object */
  256. rwlock_t sched_lock; /* lock sched_data */
  257. void *sched_data; /* scheduler application data */
  258. };
  259. /*
  260. * The real server destination forwarding entry
  261. * with ip address, port number, and so on.
  262. */
  263. struct ip_vs_dest {
  264. struct list_head n_list; /* for the dests in the service */
  265. struct list_head d_list; /* for table with all the dests */
  266. __be32 addr; /* IP address of the server */
  267. __be16 port; /* port number of the server */
  268. volatile unsigned flags; /* dest status flags */
  269. atomic_t conn_flags; /* flags to copy to conn */
  270. atomic_t weight; /* server weight */
  271. atomic_t refcnt; /* reference counter */
  272. struct ip_vs_stats stats; /* statistics */
  273. /* connection counters and thresholds */
  274. atomic_t activeconns; /* active connections */
  275. atomic_t inactconns; /* inactive connections */
  276. atomic_t persistconns; /* persistent connections */
  277. __u32 u_threshold; /* upper threshold */
  278. __u32 l_threshold; /* lower threshold */
  279. /* for destination cache */
  280. spinlock_t dst_lock; /* lock of dst_cache */
  281. struct dst_entry *dst_cache; /* destination cache entry */
  282. u32 dst_rtos; /* RT_TOS(tos) for dst */
  283. /* for virtual service */
  284. struct ip_vs_service *svc; /* service it belongs to */
  285. __u16 protocol; /* which protocol (TCP/UDP) */
  286. __be32 vaddr; /* virtual IP address */
  287. __be16 vport; /* virtual port number */
  288. __u32 vfwmark; /* firewall mark of service */
  289. };
  290. /*
  291. * The scheduler object
  292. */
  293. struct ip_vs_scheduler {
  294. struct list_head n_list; /* d-linked list head */
  295. char *name; /* scheduler name */
  296. atomic_t refcnt; /* reference counter */
  297. struct module *module; /* THIS_MODULE/NULL */
  298. /* scheduler initializing service */
  299. int (*init_service)(struct ip_vs_service *svc);
  300. /* scheduling service finish */
  301. int (*done_service)(struct ip_vs_service *svc);
  302. /* scheduler updating service */
  303. int (*update_service)(struct ip_vs_service *svc);
  304. /* selecting a server from the given service */
  305. struct ip_vs_dest* (*schedule)(struct ip_vs_service *svc,
  306. const struct sk_buff *skb);
  307. };
  308. /*
  309. * The application module object (a.k.a. app incarnation)
  310. */
  311. struct ip_vs_app
  312. {
  313. struct list_head a_list; /* member in app list */
  314. int type; /* IP_VS_APP_TYPE_xxx */
  315. char *name; /* application module name */
  316. __u16 protocol;
  317. struct module *module; /* THIS_MODULE/NULL */
  318. struct list_head incs_list; /* list of incarnations */
  319. /* members for application incarnations */
  320. struct list_head p_list; /* member in proto app list */
  321. struct ip_vs_app *app; /* its real application */
  322. __be16 port; /* port number in net order */
  323. atomic_t usecnt; /* usage counter */
  324. /* output hook: return false if can't linearize. diff set for TCP. */
  325. int (*pkt_out)(struct ip_vs_app *, struct ip_vs_conn *,
  326. struct sk_buff *, int *diff);
  327. /* input hook: return false if can't linearize. diff set for TCP. */
  328. int (*pkt_in)(struct ip_vs_app *, struct ip_vs_conn *,
  329. struct sk_buff *, int *diff);
  330. /* ip_vs_app initializer */
  331. int (*init_conn)(struct ip_vs_app *, struct ip_vs_conn *);
  332. /* ip_vs_app finish */
  333. int (*done_conn)(struct ip_vs_app *, struct ip_vs_conn *);
  334. /* not used now */
  335. int (*bind_conn)(struct ip_vs_app *, struct ip_vs_conn *,
  336. struct ip_vs_protocol *);
  337. void (*unbind_conn)(struct ip_vs_app *, struct ip_vs_conn *);
  338. int * timeout_table;
  339. int * timeouts;
  340. int timeouts_size;
  341. int (*conn_schedule)(struct sk_buff *skb, struct ip_vs_app *app,
  342. int *verdict, struct ip_vs_conn **cpp);
  343. struct ip_vs_conn *
  344. (*conn_in_get)(const struct sk_buff *skb, struct ip_vs_app *app,
  345. const struct iphdr *iph, unsigned int proto_off,
  346. int inverse);
  347. struct ip_vs_conn *
  348. (*conn_out_get)(const struct sk_buff *skb, struct ip_vs_app *app,
  349. const struct iphdr *iph, unsigned int proto_off,
  350. int inverse);
  351. int (*state_transition)(struct ip_vs_conn *cp, int direction,
  352. const struct sk_buff *skb,
  353. struct ip_vs_app *app);
  354. void (*timeout_change)(struct ip_vs_app *app, int flags);
  355. };
  356. /*
  357. * IPVS core functions
  358. * (from ip_vs_core.c)
  359. */
  360. extern const char *ip_vs_proto_name(unsigned proto);
  361. extern void ip_vs_init_hash_table(struct list_head *table, int rows);
  362. #define IP_VS_INIT_HASH_TABLE(t) ip_vs_init_hash_table(t, sizeof(t)/sizeof(t[0]))
  363. #define IP_VS_APP_TYPE_FTP 1
  364. /*
  365. * ip_vs_conn handling functions
  366. * (from ip_vs_conn.c)
  367. */
  368. /*
  369. * IPVS connection entry hash table
  370. */
  371. #ifndef CONFIG_IP_VS_TAB_BITS
  372. #define CONFIG_IP_VS_TAB_BITS 12
  373. #endif
  374. /* make sure that IP_VS_CONN_TAB_BITS is located in [8, 20] */
  375. #if CONFIG_IP_VS_TAB_BITS < 8
  376. #define IP_VS_CONN_TAB_BITS 8
  377. #endif
  378. #if CONFIG_IP_VS_TAB_BITS > 20
  379. #define IP_VS_CONN_TAB_BITS 20
  380. #endif
  381. #if 8 <= CONFIG_IP_VS_TAB_BITS && CONFIG_IP_VS_TAB_BITS <= 20
  382. #define IP_VS_CONN_TAB_BITS CONFIG_IP_VS_TAB_BITS
  383. #endif
  384. #define IP_VS_CONN_TAB_SIZE (1 << IP_VS_CONN_TAB_BITS)
  385. #define IP_VS_CONN_TAB_MASK (IP_VS_CONN_TAB_SIZE - 1)
  386. enum {
  387. IP_VS_DIR_INPUT = 0,
  388. IP_VS_DIR_OUTPUT,
  389. IP_VS_DIR_INPUT_ONLY,
  390. IP_VS_DIR_LAST,
  391. };
  392. extern struct ip_vs_conn *ip_vs_conn_in_get
  393. (int protocol, __be32 s_addr, __be16 s_port, __be32 d_addr, __be16 d_port);
  394. extern struct ip_vs_conn *ip_vs_ct_in_get
  395. (int protocol, __be32 s_addr, __be16 s_port, __be32 d_addr, __be16 d_port);
  396. extern struct ip_vs_conn *ip_vs_conn_out_get
  397. (int protocol, __be32 s_addr, __be16 s_port, __be32 d_addr, __be16 d_port);
  398. /* put back the conn without restarting its timer */
  399. static inline void __ip_vs_conn_put(struct ip_vs_conn *cp)
  400. {
  401. atomic_dec(&cp->refcnt);
  402. }
  403. extern void ip_vs_conn_put(struct ip_vs_conn *cp);
  404. extern void ip_vs_conn_fill_cport(struct ip_vs_conn *cp, __be16 cport);
  405. extern struct ip_vs_conn *
  406. ip_vs_conn_new(int proto, __be32 caddr, __be16 cport, __be32 vaddr, __be16 vport,
  407. __be32 daddr, __be16 dport, unsigned flags,
  408. struct ip_vs_dest *dest);
  409. extern void ip_vs_conn_expire_now(struct ip_vs_conn *cp);
  410. extern const char * ip_vs_state_name(__u16 proto, int state);
  411. extern void ip_vs_tcp_conn_listen(struct ip_vs_conn *cp);
  412. extern int ip_vs_check_template(struct ip_vs_conn *ct);
  413. extern void ip_vs_random_dropentry(void);
  414. extern int ip_vs_conn_init(void);
  415. extern void ip_vs_conn_cleanup(void);
  416. static inline void ip_vs_control_del(struct ip_vs_conn *cp)
  417. {
  418. struct ip_vs_conn *ctl_cp = cp->control;
  419. if (!ctl_cp) {
  420. IP_VS_ERR("request control DEL for uncontrolled: "
  421. "%d.%d.%d.%d:%d to %d.%d.%d.%d:%d\n",
  422. NIPQUAD(cp->caddr),ntohs(cp->cport),
  423. NIPQUAD(cp->vaddr),ntohs(cp->vport));
  424. return;
  425. }
  426. IP_VS_DBG(7, "DELeting control for: "
  427. "cp.dst=%d.%d.%d.%d:%d ctl_cp.dst=%d.%d.%d.%d:%d\n",
  428. NIPQUAD(cp->caddr),ntohs(cp->cport),
  429. NIPQUAD(ctl_cp->caddr),ntohs(ctl_cp->cport));
  430. cp->control = NULL;
  431. if (atomic_read(&ctl_cp->n_control) == 0) {
  432. IP_VS_ERR("BUG control DEL with n=0 : "
  433. "%d.%d.%d.%d:%d to %d.%d.%d.%d:%d\n",
  434. NIPQUAD(cp->caddr),ntohs(cp->cport),
  435. NIPQUAD(cp->vaddr),ntohs(cp->vport));
  436. return;
  437. }
  438. atomic_dec(&ctl_cp->n_control);
  439. }
  440. static inline void
  441. ip_vs_control_add(struct ip_vs_conn *cp, struct ip_vs_conn *ctl_cp)
  442. {
  443. if (cp->control) {
  444. IP_VS_ERR("request control ADD for already controlled: "
  445. "%d.%d.%d.%d:%d to %d.%d.%d.%d:%d\n",
  446. NIPQUAD(cp->caddr),ntohs(cp->cport),
  447. NIPQUAD(cp->vaddr),ntohs(cp->vport));
  448. ip_vs_control_del(cp);
  449. }
  450. IP_VS_DBG(7, "ADDing control for: "
  451. "cp.dst=%d.%d.%d.%d:%d ctl_cp.dst=%d.%d.%d.%d:%d\n",
  452. NIPQUAD(cp->caddr),ntohs(cp->cport),
  453. NIPQUAD(ctl_cp->caddr),ntohs(ctl_cp->cport));
  454. cp->control = ctl_cp;
  455. atomic_inc(&ctl_cp->n_control);
  456. }
  457. /*
  458. * IPVS application functions
  459. * (from ip_vs_app.c)
  460. */
  461. #define IP_VS_APP_MAX_PORTS 8
  462. extern int register_ip_vs_app(struct ip_vs_app *app);
  463. extern void unregister_ip_vs_app(struct ip_vs_app *app);
  464. extern int ip_vs_bind_app(struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
  465. extern void ip_vs_unbind_app(struct ip_vs_conn *cp);
  466. extern int
  467. register_ip_vs_app_inc(struct ip_vs_app *app, __u16 proto, __u16 port);
  468. extern int ip_vs_app_inc_get(struct ip_vs_app *inc);
  469. extern void ip_vs_app_inc_put(struct ip_vs_app *inc);
  470. extern int ip_vs_app_pkt_out(struct ip_vs_conn *, struct sk_buff *skb);
  471. extern int ip_vs_app_pkt_in(struct ip_vs_conn *, struct sk_buff *skb);
  472. extern int ip_vs_skb_replace(struct sk_buff *skb, gfp_t pri,
  473. char *o_buf, int o_len, char *n_buf, int n_len);
  474. extern int ip_vs_app_init(void);
  475. extern void ip_vs_app_cleanup(void);
  476. /*
  477. * IPVS protocol functions (from ip_vs_proto.c)
  478. */
  479. extern int ip_vs_protocol_init(void);
  480. extern void ip_vs_protocol_cleanup(void);
  481. extern void ip_vs_protocol_timeout_change(int flags);
  482. extern int *ip_vs_create_timeout_table(int *table, int size);
  483. extern int
  484. ip_vs_set_state_timeout(int *table, int num, char **names, char *name, int to);
  485. extern void
  486. ip_vs_tcpudp_debug_packet(struct ip_vs_protocol *pp, const struct sk_buff *skb,
  487. int offset, const char *msg);
  488. extern struct ip_vs_protocol ip_vs_protocol_tcp;
  489. extern struct ip_vs_protocol ip_vs_protocol_udp;
  490. extern struct ip_vs_protocol ip_vs_protocol_icmp;
  491. extern struct ip_vs_protocol ip_vs_protocol_esp;
  492. extern struct ip_vs_protocol ip_vs_protocol_ah;
  493. /*
  494. * Registering/unregistering scheduler functions
  495. * (from ip_vs_sched.c)
  496. */
  497. extern int register_ip_vs_scheduler(struct ip_vs_scheduler *scheduler);
  498. extern int unregister_ip_vs_scheduler(struct ip_vs_scheduler *scheduler);
  499. extern int ip_vs_bind_scheduler(struct ip_vs_service *svc,
  500. struct ip_vs_scheduler *scheduler);
  501. extern int ip_vs_unbind_scheduler(struct ip_vs_service *svc);
  502. extern struct ip_vs_scheduler *ip_vs_scheduler_get(const char *sched_name);
  503. extern void ip_vs_scheduler_put(struct ip_vs_scheduler *scheduler);
  504. extern struct ip_vs_conn *
  505. ip_vs_schedule(struct ip_vs_service *svc, const struct sk_buff *skb);
  506. extern int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
  507. struct ip_vs_protocol *pp);
  508. /*
  509. * IPVS control data and functions (from ip_vs_ctl.c)
  510. */
  511. extern int sysctl_ip_vs_cache_bypass;
  512. extern int sysctl_ip_vs_expire_nodest_conn;
  513. extern int sysctl_ip_vs_expire_quiescent_template;
  514. extern int sysctl_ip_vs_sync_threshold[2];
  515. extern int sysctl_ip_vs_nat_icmp_send;
  516. extern struct ip_vs_stats ip_vs_stats;
  517. extern struct ctl_path net_vs_ctl_path[];
  518. extern struct ip_vs_service *
  519. ip_vs_service_get(__u32 fwmark, __u16 protocol, __be32 vaddr, __be16 vport);
  520. static inline void ip_vs_service_put(struct ip_vs_service *svc)
  521. {
  522. atomic_dec(&svc->usecnt);
  523. }
  524. extern struct ip_vs_dest *
  525. ip_vs_lookup_real_service(__u16 protocol, __be32 daddr, __be16 dport);
  526. extern int ip_vs_use_count_inc(void);
  527. extern void ip_vs_use_count_dec(void);
  528. extern int ip_vs_control_init(void);
  529. extern void ip_vs_control_cleanup(void);
  530. extern struct ip_vs_dest *
  531. ip_vs_find_dest(__be32 daddr, __be16 dport,
  532. __be32 vaddr, __be16 vport, __u16 protocol);
  533. extern struct ip_vs_dest *ip_vs_try_bind_dest(struct ip_vs_conn *cp);
  534. /*
  535. * IPVS sync daemon data and function prototypes
  536. * (from ip_vs_sync.c)
  537. */
  538. extern volatile int ip_vs_sync_state;
  539. extern volatile int ip_vs_master_syncid;
  540. extern volatile int ip_vs_backup_syncid;
  541. extern char ip_vs_master_mcast_ifn[IP_VS_IFNAME_MAXLEN];
  542. extern char ip_vs_backup_mcast_ifn[IP_VS_IFNAME_MAXLEN];
  543. extern int start_sync_thread(int state, char *mcast_ifn, __u8 syncid);
  544. extern int stop_sync_thread(int state);
  545. extern void ip_vs_sync_conn(struct ip_vs_conn *cp);
  546. /*
  547. * IPVS rate estimator prototypes (from ip_vs_est.c)
  548. */
  549. extern int ip_vs_new_estimator(struct ip_vs_stats *stats);
  550. extern void ip_vs_kill_estimator(struct ip_vs_stats *stats);
  551. extern void ip_vs_zero_estimator(struct ip_vs_stats *stats);
  552. /*
  553. * Various IPVS packet transmitters (from ip_vs_xmit.c)
  554. */
  555. extern int ip_vs_null_xmit
  556. (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
  557. extern int ip_vs_bypass_xmit
  558. (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
  559. extern int ip_vs_nat_xmit
  560. (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
  561. extern int ip_vs_tunnel_xmit
  562. (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
  563. extern int ip_vs_dr_xmit
  564. (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp);
  565. extern int ip_vs_icmp_xmit
  566. (struct sk_buff *skb, struct ip_vs_conn *cp, struct ip_vs_protocol *pp, int offset);
  567. extern void ip_vs_dst_reset(struct ip_vs_dest *dest);
  568. /*
  569. * This is a simple mechanism to ignore packets when
  570. * we are loaded. Just set ip_vs_drop_rate to 'n' and
  571. * we start to drop 1/rate of the packets
  572. */
  573. extern int ip_vs_drop_rate;
  574. extern int ip_vs_drop_counter;
  575. static __inline__ int ip_vs_todrop(void)
  576. {
  577. if (!ip_vs_drop_rate) return 0;
  578. if (--ip_vs_drop_counter > 0) return 0;
  579. ip_vs_drop_counter = ip_vs_drop_rate;
  580. return 1;
  581. }
  582. /*
  583. * ip_vs_fwd_tag returns the forwarding tag of the connection
  584. */
  585. #define IP_VS_FWD_METHOD(cp) (cp->flags & IP_VS_CONN_F_FWD_MASK)
  586. static inline char ip_vs_fwd_tag(struct ip_vs_conn *cp)
  587. {
  588. char fwd;
  589. switch (IP_VS_FWD_METHOD(cp)) {
  590. case IP_VS_CONN_F_MASQ:
  591. fwd = 'M'; break;
  592. case IP_VS_CONN_F_LOCALNODE:
  593. fwd = 'L'; break;
  594. case IP_VS_CONN_F_TUNNEL:
  595. fwd = 'T'; break;
  596. case IP_VS_CONN_F_DROUTE:
  597. fwd = 'R'; break;
  598. case IP_VS_CONN_F_BYPASS:
  599. fwd = 'B'; break;
  600. default:
  601. fwd = '?'; break;
  602. }
  603. return fwd;
  604. }
  605. extern void ip_vs_nat_icmp(struct sk_buff *skb, struct ip_vs_protocol *pp,
  606. struct ip_vs_conn *cp, int dir);
  607. extern __sum16 ip_vs_checksum_complete(struct sk_buff *skb, int offset);
  608. static inline __wsum ip_vs_check_diff4(__be32 old, __be32 new, __wsum oldsum)
  609. {
  610. __be32 diff[2] = { ~old, new };
  611. return csum_partial((char *) diff, sizeof(diff), oldsum);
  612. }
  613. static inline __wsum ip_vs_check_diff2(__be16 old, __be16 new, __wsum oldsum)
  614. {
  615. __be16 diff[2] = { ~old, new };
  616. return csum_partial((char *) diff, sizeof(diff), oldsum);
  617. }
  618. #endif /* __KERNEL__ */
  619. #endif /* _NET_IP_VS_H */