OpenSDE Packages Database (without history before r20070)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

966 lines
29 KiB

  1. # --- T2-COPYRIGHT-NOTE-BEGIN ---
  2. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  3. #
  4. # T2 SDE: package/.../ipvsadm/inject_2.4.29_ip_vs.h.patch
  5. # Copyright (C) 2004 - 2006 The T2 SDE Project
  6. #
  7. # More information can be found in the files COPYING and README.
  8. #
  9. # This patch file is dual-licensed. It is available under the license the
  10. # patched project is licensed under, as long as it is an OpenSource license
  11. # as defined at http://www.opensource.org/ (e.g. BSD, X11) or under the terms
  12. # of the GNU General Public License as published by the Free Software
  13. # Foundation; either version 2 of the License, or (at your option) any later
  14. # version.
  15. # --- T2-COPYRIGHT-NOTE-END ---
  16. --- ./Makefile.orig 2005-02-03 19:09:08.000000000 -0300
  17. +++ ./Makefile 2005-02-03 19:09:23.000000000 -0300
  18. @@ -59,7 +59,7 @@
  19. echo "rpm"; \
  20. fi )
  21. -IP_VS_H_DEFINE = $(shell if [ ! -f ../ip_vs.h ]; then \
  22. +IP_VS_H_DEFINE = $(shell if [ ! -f ip_vs.h ]; then \
  23. echo "-DHAVE_NET_IP_VS_H"; fi;)
  24. ifeq (,$(FORCE_GETOPT))
  25. --- /dev/null 2004-11-09 23:14:49.000000000 -0300
  26. +++ ./ip_vs.h 2005-02-03 19:04:00.000000000 -0300
  27. @@ -0,0 +1,937 @@
  28. +/*
  29. + * IP Virtual Server
  30. + * data structure and functionality definitions
  31. + */
  32. +
  33. +#ifndef _IP_VS_H
  34. +#define _IP_VS_H
  35. +
  36. +#include <asm/types.h> /* For __uXX types */
  37. +
  38. +#define IP_VS_VERSION_CODE 0x01000C
  39. +#define NVERSION(version) \
  40. + (version >> 16) & 0xFF, \
  41. + (version >> 8) & 0xFF, \
  42. + version & 0xFF
  43. +
  44. +/*
  45. + * Virtual Service Flags
  46. + */
  47. +#define IP_VS_SVC_F_PERSISTENT 0x0001 /* persistent port */
  48. +#define IP_VS_SVC_F_HASHED 0x0002 /* hashed entry */
  49. +
  50. +/*
  51. + * Destination Server Flags
  52. + */
  53. +#define IP_VS_DEST_F_AVAILABLE 0x0001 /* Available tag */
  54. +
  55. +/*
  56. + * IPVS sync daemon states
  57. + */
  58. +#define IP_VS_STATE_NONE 0 /* daemon is stopped */
  59. +#define IP_VS_STATE_MASTER 1 /* started as master */
  60. +#define IP_VS_STATE_BACKUP 2 /* started as backup */
  61. +
  62. +/*
  63. + * IPVS socket options
  64. + */
  65. +#define IP_VS_BASE_CTL (64+1024+64) /* base */
  66. +
  67. +#define IP_VS_SO_SET_NONE IP_VS_BASE_CTL /* just peek */
  68. +#define IP_VS_SO_SET_INSERT (IP_VS_BASE_CTL+1)
  69. +#define IP_VS_SO_SET_ADD (IP_VS_BASE_CTL+2)
  70. +#define IP_VS_SO_SET_EDIT (IP_VS_BASE_CTL+3)
  71. +#define IP_VS_SO_SET_DEL (IP_VS_BASE_CTL+4)
  72. +#define IP_VS_SO_SET_FLUSH (IP_VS_BASE_CTL+5)
  73. +#define IP_VS_SO_SET_LIST (IP_VS_BASE_CTL+6)
  74. +#define IP_VS_SO_SET_ADDDEST (IP_VS_BASE_CTL+7)
  75. +#define IP_VS_SO_SET_DELDEST (IP_VS_BASE_CTL+8)
  76. +#define IP_VS_SO_SET_EDITDEST (IP_VS_BASE_CTL+9)
  77. +#define IP_VS_SO_SET_TIMEOUTS (IP_VS_BASE_CTL+10)
  78. +#define IP_VS_SO_SET_STARTDAEMON (IP_VS_BASE_CTL+11)
  79. +#define IP_VS_SO_SET_STOPDAEMON (IP_VS_BASE_CTL+12)
  80. +#define IP_VS_SO_SET_RESTORE (IP_VS_BASE_CTL+13)
  81. +#define IP_VS_SO_SET_SAVE (IP_VS_BASE_CTL+14)
  82. +#define IP_VS_SO_SET_ZERO (IP_VS_BASE_CTL+15)
  83. +#define IP_VS_SO_SET_MAX IP_VS_SO_SET_ZERO
  84. +
  85. +#define IP_VS_SO_GET_VERSION IP_VS_BASE_CTL
  86. +#define IP_VS_SO_GET_INFO (IP_VS_BASE_CTL+1)
  87. +#define IP_VS_SO_GET_SERVICES (IP_VS_BASE_CTL+2)
  88. +#define IP_VS_SO_GET_SERVICE (IP_VS_BASE_CTL+3)
  89. +#define IP_VS_SO_GET_DESTS (IP_VS_BASE_CTL+4)
  90. +#define IP_VS_SO_GET_DEST (IP_VS_BASE_CTL+5) /* not used now */
  91. +#define IP_VS_SO_GET_TIMEOUTS (IP_VS_BASE_CTL+6)
  92. +#define IP_VS_SO_GET_DAEMON (IP_VS_BASE_CTL+7)
  93. +#define IP_VS_SO_GET_MAX IP_VS_SO_GET_DAEMON
  94. +
  95. +
  96. +/*
  97. + * IPVS Connection Flags
  98. + */
  99. +#define IP_VS_CONN_F_FWD_MASK 0x0007 /* mask for the fwd methods */
  100. +#define IP_VS_CONN_F_MASQ 0x0000 /* masquerading */
  101. +#define IP_VS_CONN_F_LOCALNODE 0x0001 /* local node */
  102. +#define IP_VS_CONN_F_TUNNEL 0x0002 /* tunneling */
  103. +#define IP_VS_CONN_F_DROUTE 0x0003 /* direct routing */
  104. +#define IP_VS_CONN_F_BYPASS 0x0004 /* cache bypass */
  105. +#define IP_VS_CONN_F_HASHED 0x0040 /* hashed entry */
  106. +#define IP_VS_CONN_F_NOOUTPUT 0x0080 /* no output packets */
  107. +#define IP_VS_CONN_F_INACTIVE 0x0100 /* not established */
  108. +#define IP_VS_CONN_F_OUT_SEQ 0x0200 /* must do output seq adjust */
  109. +#define IP_VS_CONN_F_IN_SEQ 0x0400 /* must do input seq adjust */
  110. +#define IP_VS_CONN_F_SEQ_MASK 0x0600 /* in/out sequence mask */
  111. +#define IP_VS_CONN_F_NO_CPORT 0x0800 /* no client port set yet */
  112. +
  113. +/* Move it to better place one day, for now keep it unique */
  114. +#define NFC_IPVS_PROPERTY 0x10000
  115. +
  116. +#define IP_VS_SCHEDNAME_MAXLEN 16
  117. +#define IP_VS_IFNAME_MAXLEN 16
  118. +
  119. +struct ip_vs_rule_user {
  120. + /* global options */
  121. + int tcp_timeout; /* timeout values */
  122. + int tcp_fin_timeout;
  123. + int udp_timeout;
  124. + int state; /* sync daemon state */
  125. + char mcast_ifn[IP_VS_IFNAME_MAXLEN];
  126. + /* multicast interface name */
  127. + int syncid;
  128. +
  129. + /* virtual service options */
  130. + u_int16_t protocol;
  131. + u_int32_t vaddr; /* virtual address */
  132. + u_int16_t vport;
  133. + u_int32_t vfwmark; /* firwall mark of virtual service*/
  134. + char sched_name[IP_VS_SCHEDNAME_MAXLEN];
  135. + unsigned vs_flags; /* virtual service flags */
  136. + unsigned timeout; /* persistent timeout in ticks */
  137. + u_int32_t netmask; /* persistent netmask */
  138. +
  139. + /* destination specific options */
  140. + u_int32_t daddr; /* destination address */
  141. + u_int16_t dport;
  142. + unsigned conn_flags; /* destination flags */
  143. + int weight; /* destination weight */
  144. +};
  145. +
  146. +
  147. +/*
  148. + * IPVS statistics object (for user space)
  149. + */
  150. +struct ip_vs_stats_user
  151. +{
  152. + __u32 conns; /* connections scheduled */
  153. + __u32 inpkts; /* incoming packets */
  154. + __u32 outpkts; /* outgoing packets */
  155. + __u64 inbytes; /* incoming bytes */
  156. + __u64 outbytes; /* outgoing bytes */
  157. +
  158. + __u32 cps; /* current connection rate */
  159. + __u32 inpps; /* current in packet rate */
  160. + __u32 outpps; /* current out packet rate */
  161. + __u32 inbps; /* current in byte rate */
  162. + __u32 outbps; /* current out byte rate */
  163. +};
  164. +
  165. +
  166. +/* The argument to IP_VS_SO_GET_INFO */
  167. +struct ip_vs_getinfo {
  168. + /* version number */
  169. + unsigned int version;
  170. +
  171. + /* size of connection hash table */
  172. + unsigned int size;
  173. +
  174. + /* number of virtual services */
  175. + unsigned int num_services;
  176. +};
  177. +
  178. +/* The argument to IP_VS_SO_GET_SERVICE */
  179. +struct ip_vs_service_user {
  180. + /* which service: user fills this in */
  181. + u_int16_t protocol;
  182. + u_int32_t addr; /* virtual address */
  183. + u_int16_t port;
  184. + u_int32_t fwmark; /* firwall mark of virtual service */
  185. +
  186. + /* service options */
  187. + char sched_name[IP_VS_SCHEDNAME_MAXLEN];
  188. + unsigned flags; /* virtual service flags */
  189. + unsigned timeout; /* persistent timeout in ticks */
  190. + u_int32_t netmask; /* persistent netmask */
  191. +
  192. + /* number of real servers */
  193. + unsigned int num_dests;
  194. +
  195. + /* statistics */
  196. + struct ip_vs_stats_user stats;
  197. +};
  198. +
  199. +struct ip_vs_dest_user {
  200. + u_int32_t addr; /* destination address */
  201. + u_int16_t port;
  202. + unsigned flags; /* destination flags */
  203. + int weight; /* destination weight */
  204. + u_int32_t activeconns; /* active connections */
  205. + u_int32_t inactconns; /* inactive connections */
  206. +
  207. + /* statistics */
  208. + struct ip_vs_stats_user stats;
  209. +};
  210. +
  211. +/* The argument to IP_VS_SO_GET_DESTS */
  212. +struct ip_vs_get_dests {
  213. + /* which service: user fills this in */
  214. + u_int16_t protocol;
  215. + u_int32_t addr; /* virtual address */
  216. + u_int16_t port;
  217. + u_int32_t fwmark; /* firwall mark of virtual service */
  218. +
  219. + /* number of real servers */
  220. + unsigned int num_dests;
  221. +
  222. + /* the real servers */
  223. + struct ip_vs_dest_user entrytable[0];
  224. +};
  225. +
  226. +/* The argument to IP_VS_SO_GET_SERVICES */
  227. +struct ip_vs_get_services {
  228. + /* number of virtual services */
  229. + unsigned int num_services;
  230. +
  231. + /* service table */
  232. + struct ip_vs_service_user entrytable[0];
  233. +};
  234. +
  235. +/* The argument to IP_VS_SO_GET_TIMEOUTS */
  236. +struct ip_vs_timeout_user {
  237. + int tcp_timeout;
  238. + int tcp_fin_timeout;
  239. + int udp_timeout;
  240. +};
  241. +
  242. +/* The argument to IP_VS_SO_GET_DAEMON */
  243. +struct ip_vs_daemon_user {
  244. + int state; /* sync daemon state */
  245. + char mcast_master_ifn[IP_VS_IFNAME_MAXLEN]; /* mcast master interface name */
  246. + char mcast_backup_ifn[IP_VS_IFNAME_MAXLEN]; /* mcast backup interface name */
  247. +};
  248. +
  249. +
  250. +#ifdef __KERNEL__
  251. +
  252. +#include <linux/config.h>
  253. +#include <linux/list.h> /* for struct list_head */
  254. +#include <linux/spinlock.h> /* for struct rwlock_t */
  255. +#include <linux/skbuff.h> /* for struct sk_buff */
  256. +#include <linux/ip.h> /* for struct iphdr */
  257. +#include <asm/atomic.h> /* for struct atomic_t */
  258. +#include <linux/netdevice.h> /* for struct neighbour; */
  259. +#include <net/dst.h> /* for struct dst_entry */
  260. +#include <net/route.h> /* for ip_route_output */
  261. +#include <net/tcp.h>
  262. +#include <net/udp.h>
  263. +
  264. +
  265. +#ifdef CONFIG_IP_VS_DEBUG
  266. +extern int ip_vs_get_debug_level(void);
  267. +#define IP_VS_DBG(level, msg...) \
  268. + do { \
  269. + if (level <= ip_vs_get_debug_level()) \
  270. + printk(KERN_DEBUG "IPVS: " msg); \
  271. + } while (0)
  272. +#define IP_VS_DBG_RL(msg...) \
  273. + do { \
  274. + if (net_ratelimit()) \
  275. + printk(KERN_DEBUG "IPVS: " msg); \
  276. + } while (0)
  277. +#else /* NO DEBUGGING at ALL */
  278. +#define IP_VS_DBG(level, msg...) do {} while (0)
  279. +#define IP_VS_DBG_RL(msg...) do {} while (0)
  280. +#endif
  281. +
  282. +#define IP_VS_BUG() BUG()
  283. +#define IP_VS_ERR(msg...) printk(KERN_ERR "IPVS: " msg)
  284. +#define IP_VS_INFO(msg...) printk(KERN_INFO "IPVS: " msg)
  285. +#define IP_VS_WARNING(msg...) \
  286. + printk(KERN_WARNING "IPVS: " msg)
  287. +#define IP_VS_ERR_RL(msg...) \
  288. + do { \
  289. + if (net_ratelimit()) \
  290. + printk(KERN_ERR "IPVS: " msg); \
  291. + } while (0)
  292. +
  293. +#ifdef CONFIG_IP_VS_DEBUG
  294. +#define EnterFunction(level) \
  295. + do { \
  296. + if (level <= ip_vs_get_debug_level()) \
  297. + printk(KERN_DEBUG "Enter: %s, %s line %i\n", \
  298. + __FUNCTION__, __FILE__, __LINE__); \
  299. + } while (0)
  300. +#define LeaveFunction(level) \
  301. + do { \
  302. + if (level <= ip_vs_get_debug_level()) \
  303. + printk(KERN_DEBUG "Leave: %s, %s line %i\n", \
  304. + __FUNCTION__, __FILE__, __LINE__); \
  305. + } while (0)
  306. +#else
  307. +#define EnterFunction(level) do {} while (0)
  308. +#define LeaveFunction(level) do {} while (0)
  309. +#endif
  310. +
  311. +
  312. +/*
  313. + * The port number of FTP service (in network order).
  314. + */
  315. +#define FTPPORT __constant_htons(21)
  316. +#define FTPDATA __constant_htons(20)
  317. +
  318. +
  319. +/*
  320. + * IPVS sysctl variables under the /proc/sys/net/ipv4/vs/
  321. + */
  322. +#define NET_IPV4_VS 21
  323. +
  324. +enum {
  325. + NET_IPV4_VS_DEBUG_LEVEL=1,
  326. + NET_IPV4_VS_AMEMTHRESH=2,
  327. + NET_IPV4_VS_AMDROPRATE=3,
  328. + NET_IPV4_VS_DROP_ENTRY=4,
  329. + NET_IPV4_VS_DROP_PACKET=5,
  330. + NET_IPV4_VS_SECURE_TCP=6,
  331. + NET_IPV4_VS_TO_ES=7,
  332. + NET_IPV4_VS_TO_SS=8,
  333. + NET_IPV4_VS_TO_SR=9,
  334. + NET_IPV4_VS_TO_FW=10,
  335. + NET_IPV4_VS_TO_TW=11,
  336. + NET_IPV4_VS_TO_CL=12,
  337. + NET_IPV4_VS_TO_CW=13,
  338. + NET_IPV4_VS_TO_LA=14,
  339. + NET_IPV4_VS_TO_LI=15,
  340. + NET_IPV4_VS_TO_SA=16,
  341. + NET_IPV4_VS_TO_UDP=17,
  342. + NET_IPV4_VS_TO_ICMP=18,
  343. + NET_IPV4_VS_LBLC_EXPIRE=19,
  344. + NET_IPV4_VS_LBLCR_EXPIRE=20,
  345. + NET_IPV4_VS_CACHE_BYPASS=22,
  346. + NET_IPV4_VS_EXPIRE_NODEST_CONN=23,
  347. + NET_IPV4_VS_SYNC_THRESHOLD=24,
  348. + NET_IPV4_VS_NAT_ICMP_SEND=25,
  349. + NET_IPV4_VS_EXPIRE_QUIESCENT_TEMPLATE=26,
  350. + NET_IPV4_VS_LAST
  351. +};
  352. +
  353. +
  354. +/*
  355. + * IPVS State Values
  356. + */
  357. +enum {
  358. + IP_VS_S_NONE = 0,
  359. + IP_VS_S_ESTABLISHED,
  360. + IP_VS_S_SYN_SENT,
  361. + IP_VS_S_SYN_RECV,
  362. + IP_VS_S_FIN_WAIT,
  363. + IP_VS_S_TIME_WAIT,
  364. + IP_VS_S_CLOSE,
  365. + IP_VS_S_CLOSE_WAIT,
  366. + IP_VS_S_LAST_ACK,
  367. + IP_VS_S_LISTEN,
  368. + IP_VS_S_SYNACK,
  369. + IP_VS_S_UDP,
  370. + IP_VS_S_ICMP,
  371. + IP_VS_S_LAST
  372. +};
  373. +
  374. +
  375. +struct ip_vs_timeout_table {
  376. + atomic_t refcnt;
  377. + int scale;
  378. + int timeout[IP_VS_S_LAST+1];
  379. +};
  380. +
  381. +
  382. +/*
  383. + * Transport protocol header
  384. + */
  385. +union ip_vs_tphdr {
  386. + unsigned char *raw;
  387. + struct udphdr *uh;
  388. + struct tcphdr *th;
  389. + struct icmphdr *icmph;
  390. + __u16 *portp;
  391. +};
  392. +
  393. +
  394. +/*
  395. + * Delta sequence info structure
  396. + * Each ip_vs_conn has 2 (output AND input seq. changes).
  397. + * Only used in the VS/NAT.
  398. + */
  399. +struct ip_vs_seq {
  400. + __u32 init_seq; /* Add delta from this seq */
  401. + __u32 delta; /* Delta in sequence numbers */
  402. + __u32 previous_delta; /* Delta in sequence numbers
  403. + before last resized pkt */
  404. +};
  405. +
  406. +
  407. +/*
  408. + * IPVS statistics object
  409. + */
  410. +struct ip_vs_stats
  411. +{
  412. + __u32 conns; /* connections scheduled */
  413. + __u32 inpkts; /* incoming packets */
  414. + __u32 outpkts; /* outgoing packets */
  415. + __u64 inbytes; /* incoming bytes */
  416. + __u64 outbytes; /* outgoing bytes */
  417. +
  418. + __u32 cps; /* current connection rate */
  419. + __u32 inpps; /* current in packet rate */
  420. + __u32 outpps; /* current out packet rate */
  421. + __u32 inbps; /* current in byte rate */
  422. + __u32 outbps; /* current out byte rate */
  423. +
  424. + spinlock_t lock; /* spin lock */
  425. +};
  426. +
  427. +
  428. +/*
  429. + * IP_VS structure allocated for each dynamically scheduled connection
  430. + */
  431. +struct ip_vs_conn {
  432. + struct list_head c_list; /* hashed list heads */
  433. +
  434. + /* Protocol, addresses and port numbers */
  435. + __u32 caddr; /* client address */
  436. + __u32 vaddr; /* virtual address */
  437. + __u32 daddr; /* destination address */
  438. + __u16 cport;
  439. + __u16 vport;
  440. + __u16 dport;
  441. + __u16 protocol; /* Which protocol (TCP/UDP) */
  442. +
  443. + /* counter and timer */
  444. + atomic_t refcnt; /* reference count */
  445. + struct timer_list timer; /* Expiration timer */
  446. + volatile unsigned long timeout; /* timeout */
  447. + struct ip_vs_timeout_table *timeout_table;
  448. +
  449. + /* Flags and state transition */
  450. + spinlock_t lock; /* lock for state transition */
  451. + volatile __u16 flags; /* status flags */
  452. + volatile __u16 state; /* state info */
  453. +
  454. + /* Control members */
  455. + struct ip_vs_conn *control; /* Master control connection */
  456. + atomic_t n_control; /* Number of controlled ones */
  457. + struct ip_vs_dest *dest; /* real server */
  458. + atomic_t in_pkts; /* incoming packet counter */
  459. +
  460. + /* packet transmitter for different forwarding methods */
  461. + int (*packet_xmit)(struct sk_buff *skb, struct ip_vs_conn *cp);
  462. +
  463. + /* Note: we can group the following members into a structure,
  464. + in order to save more space, and the following members are
  465. + only used in VS/NAT anyway */
  466. + struct ip_vs_app *app; /* bound ip_vs_app object */
  467. + void *app_data; /* Application private data */
  468. + struct ip_vs_seq in_seq; /* incoming seq. struct */
  469. + struct ip_vs_seq out_seq; /* outgoing seq. struct */
  470. +};
  471. +
  472. +
  473. +/*
  474. + * The information about the virtual service offered to the net
  475. + * and the forwarding entries
  476. + */
  477. +struct ip_vs_service {
  478. + struct list_head s_list; /* for normal service table */
  479. + struct list_head f_list; /* for fwmark-based service table */
  480. + atomic_t refcnt; /* reference counter */
  481. + atomic_t usecnt; /* use counter */
  482. +
  483. + __u16 protocol; /* which protocol (TCP/UDP) */
  484. + __u32 addr; /* IP address for virtual service */
  485. + __u16 port; /* port number for the service */
  486. + __u32 fwmark; /* firewall mark of the service */
  487. + unsigned flags; /* service status flags */
  488. + unsigned timeout; /* persistent timeout in ticks */
  489. + __u32 netmask; /* grouping granularity */
  490. +
  491. + struct list_head destinations; /* real server d-linked list */
  492. + __u32 num_dests; /* number of servers */
  493. + struct ip_vs_stats stats; /* statistics for the service */
  494. +
  495. + /* for scheduling */
  496. + struct ip_vs_scheduler *scheduler; /* bound scheduler object */
  497. + rwlock_t sched_lock; /* lock sched_data */
  498. + void *sched_data; /* scheduler application data */
  499. +};
  500. +
  501. +
  502. +/*
  503. + * The real server destination forwarding entry
  504. + * with ip address, port number, and so on.
  505. + */
  506. +struct ip_vs_dest {
  507. + struct list_head n_list; /* for the dests in the service */
  508. + struct list_head d_list; /* for table with all the dests */
  509. +
  510. + __u32 addr; /* IP address of real server */
  511. + __u16 port; /* port number of the service */
  512. + unsigned flags; /* dest status flags */
  513. + atomic_t weight; /* server weight */
  514. + atomic_t conn_flags; /* flags to copy to conn */
  515. + atomic_t activeconns; /* active connections */
  516. + atomic_t inactconns; /* inactive connections */
  517. + atomic_t refcnt; /* reference counter */
  518. + struct ip_vs_stats stats; /* statistics */
  519. +
  520. + /* for destination cache */
  521. + spinlock_t dst_lock; /* lock dst_cache */
  522. + struct dst_entry *dst_cache; /* destination cache entry */
  523. + u32 dst_rtos; /* RT_TOS(tos) for dst */
  524. +
  525. + /* for virtual service */
  526. + struct ip_vs_service *svc; /* service that it belongs to */
  527. + __u16 protocol; /* which protocol (TCP/UDP) */
  528. + __u32 vaddr; /* IP address for virtual service */
  529. + __u16 vport; /* port number for the service */
  530. + __u32 vfwmark; /* firewall mark of the service */
  531. +};
  532. +
  533. +
  534. +/*
  535. + * The scheduler object
  536. + */
  537. +struct ip_vs_scheduler {
  538. + struct list_head n_list; /* d-linked list head */
  539. + char *name; /* scheduler name */
  540. + atomic_t refcnt; /* reference counter */
  541. + struct module *module; /* THIS_MODULE/NULL */
  542. +
  543. + /* scheduler initializing service */
  544. + int (*init_service)(struct ip_vs_service *svc);
  545. + /* scheduling service finish */
  546. + int (*done_service)(struct ip_vs_service *svc);
  547. + /* scheduler updating service */
  548. + int (*update_service)(struct ip_vs_service *svc);
  549. +
  550. + /* selecting a server from the given service */
  551. + struct ip_vs_dest* (*schedule)(struct ip_vs_service *svc,
  552. + struct iphdr *iph);
  553. +};
  554. +
  555. +
  556. +/*
  557. + * The application module object
  558. + */
  559. +struct ip_vs_app
  560. +{
  561. + struct list_head n_list; /* d-linked list head */
  562. + char *name; /* name of application module */
  563. + unsigned type; /* type = proto<<16 | port
  564. + (host byte order)*/
  565. + struct module *module; /* THIS_MODULE/NULL */
  566. +
  567. + /* ip_vs_app initializer */
  568. + int (*init_conn)(struct ip_vs_app *, struct ip_vs_conn *);
  569. + /* ip_vs_app finish */
  570. + int (*done_conn)(struct ip_vs_app *, struct ip_vs_conn *);
  571. + /* output hook */
  572. + int (*pkt_out)(struct ip_vs_app *,
  573. + struct ip_vs_conn *, struct sk_buff *);
  574. + /* input hook */
  575. + int (*pkt_in)(struct ip_vs_app *,
  576. + struct ip_vs_conn *, struct sk_buff *);
  577. +};
  578. +
  579. +
  580. +/*
  581. + * IPVS core functions
  582. + * (from ip_vs_core.c)
  583. + */
  584. +extern const char *ip_vs_proto_name(unsigned proto);
  585. +extern unsigned int check_for_ip_vs_out(struct sk_buff **skb_p,
  586. + int (*okfn)(struct sk_buff *));
  587. +
  588. +
  589. +/*
  590. + * ip_vs_conn handling functions
  591. + * (from ip_vs_conn.c)
  592. + */
  593. +
  594. +/*
  595. + * IPVS connection entry hash table
  596. + */
  597. +#ifndef CONFIG_IP_VS_TAB_BITS
  598. +#define CONFIG_IP_VS_TAB_BITS 12
  599. +#endif
  600. +/* make sure that IP_VS_CONN_TAB_BITS is located in [8, 20] */
  601. +#if CONFIG_IP_VS_TAB_BITS < 8
  602. +#define IP_VS_CONN_TAB_BITS 8
  603. +#endif
  604. +#if CONFIG_IP_VS_TAB_BITS > 20
  605. +#define IP_VS_CONN_TAB_BITS 20
  606. +#endif
  607. +#if 8 <= CONFIG_IP_VS_TAB_BITS && CONFIG_IP_VS_TAB_BITS <= 20
  608. +#define IP_VS_CONN_TAB_BITS CONFIG_IP_VS_TAB_BITS
  609. +#endif
  610. +#define IP_VS_CONN_TAB_SIZE (1 << IP_VS_CONN_TAB_BITS)
  611. +#define IP_VS_CONN_TAB_MASK (IP_VS_CONN_TAB_SIZE - 1)
  612. +
  613. +#define VS_STATE_INPUT 0
  614. +#define VS_STATE_OUTPUT 4
  615. +#define VS_STATE_INPUT_ONLY 8
  616. +
  617. +extern struct ip_vs_timeout_table vs_timeout_table;
  618. +extern struct ip_vs_timeout_table vs_timeout_table_dos;
  619. +
  620. +extern struct ip_vs_conn *ip_vs_conn_in_get
  621. +(int protocol, __u32 s_addr, __u16 s_port, __u32 d_addr, __u16 d_port);
  622. +extern struct ip_vs_conn *ip_vs_conn_out_get
  623. +(int protocol, __u32 s_addr, __u16 s_port, __u32 d_addr, __u16 d_port);
  624. +
  625. +/* put back the conn without restarting its timer */
  626. +static inline void __ip_vs_conn_put(struct ip_vs_conn *cp)
  627. +{
  628. + atomic_dec(&cp->refcnt);
  629. +}
  630. +extern void ip_vs_conn_put(struct ip_vs_conn *cp);
  631. +
  632. +extern struct ip_vs_conn *
  633. +ip_vs_conn_new(int proto, __u32 caddr, __u16 cport, __u32 vaddr, __u16 vport,
  634. + __u32 daddr, __u16 dport, unsigned flags,
  635. + struct ip_vs_dest *dest);
  636. +extern void ip_vs_conn_expire_now(struct ip_vs_conn *cp);
  637. +
  638. +extern const char * ip_vs_state_name(int state);
  639. +extern int ip_vs_set_state(struct ip_vs_conn *cp, int state_off,
  640. + struct iphdr *iph, void *tp);
  641. +extern int ip_vs_conn_listen(struct ip_vs_conn *cp);
  642. +extern int ip_vs_check_template(struct ip_vs_conn *ct);
  643. +extern void ip_vs_secure_tcp_set(int on);
  644. +extern void ip_vs_random_dropentry(void);
  645. +extern int ip_vs_conn_init(void);
  646. +extern void ip_vs_conn_cleanup(void);
  647. +
  648. +static inline void ip_vs_control_del(struct ip_vs_conn *cp)
  649. +{
  650. + struct ip_vs_conn *ctl_cp = cp->control;
  651. + if (!ctl_cp) {
  652. + IP_VS_ERR("request control DEL for uncontrolled: "
  653. + "%d.%d.%d.%d:%d to %d.%d.%d.%d:%d\n",
  654. + NIPQUAD(cp->caddr),ntohs(cp->cport),
  655. + NIPQUAD(cp->vaddr),ntohs(cp->vport));
  656. + return;
  657. + }
  658. +
  659. + IP_VS_DBG(7, "DELeting control for: "
  660. + "cp.dst=%d.%d.%d.%d:%d ctl_cp.dst=%d.%d.%d.%d:%d\n",
  661. + NIPQUAD(cp->caddr),ntohs(cp->cport),
  662. + NIPQUAD(ctl_cp->caddr),ntohs(ctl_cp->cport));
  663. +
  664. + cp->control = NULL;
  665. + if (atomic_read(&ctl_cp->n_control) == 0) {
  666. + IP_VS_ERR("BUG control DEL with n=0 : "
  667. + "%d.%d.%d.%d:%d to %d.%d.%d.%d:%d\n",
  668. + NIPQUAD(cp->caddr),ntohs(cp->cport),
  669. + NIPQUAD(cp->vaddr),ntohs(cp->vport));
  670. + return;
  671. + }
  672. + atomic_dec(&ctl_cp->n_control);
  673. +}
  674. +
  675. +static inline void
  676. +ip_vs_control_add(struct ip_vs_conn *cp, struct ip_vs_conn *ctl_cp)
  677. +{
  678. + if (cp->control) {
  679. + IP_VS_ERR("request control ADD for already controlled: "
  680. + "%d.%d.%d.%d:%d to %d.%d.%d.%d:%d\n",
  681. + NIPQUAD(cp->caddr),ntohs(cp->cport),
  682. + NIPQUAD(cp->vaddr),ntohs(cp->vport));
  683. + ip_vs_control_del(cp);
  684. + }
  685. +
  686. + IP_VS_DBG(7, "ADDing control for: "
  687. + "cp.dst=%d.%d.%d.%d:%d ctl_cp.dst=%d.%d.%d.%d:%d\n",
  688. + NIPQUAD(cp->caddr),ntohs(cp->cport),
  689. + NIPQUAD(ctl_cp->caddr),ntohs(ctl_cp->cport));
  690. +
  691. + cp->control = ctl_cp;
  692. + atomic_inc(&ctl_cp->n_control);
  693. +}
  694. +
  695. +
  696. +/*
  697. + * IPVS application functions
  698. + * (from ip_vs_app.c)
  699. + */
  700. +#define IP_VS_APP_MAX_PORTS 8
  701. +extern int register_ip_vs_app(struct ip_vs_app *mapp,
  702. + unsigned short proto, __u16 port);
  703. +extern int unregister_ip_vs_app(struct ip_vs_app *mapp);
  704. +extern struct ip_vs_app * ip_vs_bind_app(struct ip_vs_conn *cp);
  705. +extern int ip_vs_unbind_app(struct ip_vs_conn *cp);
  706. +extern int ip_vs_app_pkt_out(struct ip_vs_conn *, struct sk_buff *skb);
  707. +extern int ip_vs_app_pkt_in(struct ip_vs_conn *, struct sk_buff *skb);
  708. +extern int ip_vs_skb_replace(struct sk_buff *skb, int pri,
  709. + char *o_buf, int o_len, char *n_buf, int n_len);
  710. +extern int ip_vs_app_init(void);
  711. +extern void ip_vs_app_cleanup(void);
  712. +
  713. +
  714. +/*
  715. + * Registering/unregistering scheduler functions
  716. + * (from ip_vs_sched.c)
  717. + */
  718. +extern int register_ip_vs_scheduler(struct ip_vs_scheduler *scheduler);
  719. +extern int unregister_ip_vs_scheduler(struct ip_vs_scheduler *scheduler);
  720. +extern int ip_vs_bind_scheduler(struct ip_vs_service *svc,
  721. + struct ip_vs_scheduler *scheduler);
  722. +extern int ip_vs_unbind_scheduler(struct ip_vs_service *svc);
  723. +extern struct ip_vs_scheduler *ip_vs_scheduler_get(const char *sched_name);
  724. +extern void ip_vs_scheduler_put(struct ip_vs_scheduler *scheduler);
  725. +
  726. +
  727. +/*
  728. + * IPVS control data and functions
  729. + * (from ip_vs_ctl.c)
  730. + */
  731. +extern int sysctl_ip_vs_cache_bypass;
  732. +extern int sysctl_ip_vs_expire_nodest_conn;
  733. +extern int sysctl_ip_vs_expire_quiescent_template;
  734. +extern int sysctl_ip_vs_sync_threshold;
  735. +extern int sysctl_ip_vs_nat_icmp_send;
  736. +extern struct ip_vs_stats ip_vs_stats;
  737. +
  738. +extern struct ip_vs_service *ip_vs_service_get(__u32 fwmark,
  739. + __u16 protocol,
  740. + __u32 vaddr, __u16 vport);
  741. +static inline void ip_vs_service_put(struct ip_vs_service *svc)
  742. +{
  743. + atomic_dec(&svc->usecnt);
  744. +}
  745. +
  746. +extern struct ip_vs_dest *
  747. +ip_vs_lookup_real_service(__u16 protocol, __u32 daddr, __u16 dport);
  748. +extern void ip_vs_random_dropentry(void);
  749. +extern int ip_vs_control_init(void);
  750. +extern void ip_vs_control_cleanup(void);
  751. +
  752. +
  753. +/*
  754. + * IPVS sync daemon data and function prototypes
  755. + * (from ip_vs_sync.c)
  756. + */
  757. +extern volatile int ip_vs_sync_state;
  758. +extern char ip_vs_mcast_master_ifn[IP_VS_IFNAME_MAXLEN];
  759. +extern char ip_vs_mcast_backup_ifn[IP_VS_IFNAME_MAXLEN];
  760. +extern int start_sync_thread(int state, char *mcast_ifn, __u8 syncid);
  761. +extern int stop_sync_thread(int state);
  762. +extern void ip_vs_sync_conn(struct ip_vs_conn *cp);
  763. +
  764. +
  765. +/*
  766. + * IPVS rate estimator prototypes (from ip_vs_est.c)
  767. + */
  768. +extern int ip_vs_new_estimator(struct ip_vs_stats *stats);
  769. +extern void ip_vs_kill_estimator(struct ip_vs_stats *stats);
  770. +extern void ip_vs_zero_estimator(struct ip_vs_stats *stats);
  771. +
  772. +
  773. +/*
  774. + * This is a simple mechanism to ignore packets when
  775. + * we are loaded. Just set ip_vs_drop_rate to 'n' and
  776. + * we start to drop 1/rate of the packets
  777. + */
  778. +extern int ip_vs_drop_rate;
  779. +extern int ip_vs_drop_counter;
  780. +
  781. +static __inline__ int ip_vs_todrop(void)
  782. +{
  783. + if (!ip_vs_drop_rate) return 0;
  784. + if (--ip_vs_drop_counter > 0) return 0;
  785. + ip_vs_drop_counter = ip_vs_drop_rate;
  786. + return 1;
  787. +}
  788. +
  789. +
  790. +/*
  791. + * ip_vs_fwd_tag returns the forwarding tag of the connection
  792. + */
  793. +#define IP_VS_FWD_METHOD(cp) (cp->flags & IP_VS_CONN_F_FWD_MASK)
  794. +
  795. +extern __inline__ char ip_vs_fwd_tag(struct ip_vs_conn *cp)
  796. +{
  797. + char fwd;
  798. +
  799. + switch (IP_VS_FWD_METHOD(cp)) {
  800. + case IP_VS_CONN_F_MASQ:
  801. + fwd = 'M'; break;
  802. + case IP_VS_CONN_F_LOCALNODE:
  803. + fwd = 'L'; break;
  804. + case IP_VS_CONN_F_TUNNEL:
  805. + fwd = 'T'; break;
  806. + case IP_VS_CONN_F_DROUTE:
  807. + fwd = 'R'; break;
  808. + case IP_VS_CONN_F_BYPASS:
  809. + fwd = 'B'; break;
  810. + default:
  811. + fwd = '?'; break;
  812. + }
  813. + return fwd;
  814. +}
  815. +
  816. +
  817. +/*
  818. + * transport layer header checking
  819. + */
  820. +extern inline int ip_vs_header_check(struct sk_buff *skb, int proto, int ihl)
  821. +{
  822. + int len;
  823. +
  824. + switch (proto) {
  825. + case IPPROTO_TCP:
  826. + len = ihl + sizeof(struct tcphdr);
  827. + /* we don't care about TCP options */
  828. + break;
  829. + case IPPROTO_UDP:
  830. + len = ihl + sizeof(struct udphdr);
  831. + break;
  832. + default:
  833. + len = 0;
  834. + }
  835. +
  836. + /* guarantee protocol header available in skb data area */
  837. + if (!pskb_may_pull(skb, len))
  838. + return -1;
  839. + else
  840. + return 0;
  841. +}
  842. +
  843. +
  844. +/*
  845. + * Destination cache
  846. + */
  847. +static inline void
  848. +__ip_vs_dst_set(struct ip_vs_dest *dest, u32 rtos, struct dst_entry *dst)
  849. +{
  850. + struct dst_entry *old_dst;
  851. +
  852. + old_dst = dest->dst_cache;
  853. + dest->dst_cache = dst;
  854. + dest->dst_rtos = rtos;
  855. + dst_release(old_dst);
  856. +}
  857. +
  858. +static inline void
  859. +__ip_vs_dst_reset(struct ip_vs_dest *dest)
  860. +{
  861. + struct dst_entry *old_dst;
  862. +
  863. + old_dst = dest->dst_cache;
  864. + dest->dst_cache = NULL;
  865. + dst_release(old_dst);
  866. +}
  867. +
  868. +static inline struct dst_entry *
  869. +__ip_vs_dst_check(struct ip_vs_dest *dest, u32 rtos, u32 cookie)
  870. +{
  871. + struct dst_entry *dst = dest->dst_cache;
  872. +
  873. + if (!dst)
  874. + return NULL;
  875. + if ((dst->obsolete || rtos != dest->dst_rtos) &&
  876. + dst->ops->check(dst, cookie) == NULL) {
  877. + dest->dst_cache = 0;
  878. + return NULL;
  879. + }
  880. + dst_hold(dst);
  881. + return dst;
  882. +}
  883. +
  884. +static inline struct rtable *
  885. +__ip_vs_get_out_rt(struct ip_vs_conn *cp, u32 rtos)
  886. +{
  887. + struct rtable *rt; /* Route to the other host */
  888. + struct ip_vs_dest *dest = cp->dest;
  889. +
  890. + if (dest) {
  891. + spin_lock(&dest->dst_lock);
  892. + if (!(rt = (struct rtable *)
  893. + __ip_vs_dst_check(dest, rtos, 0))) {
  894. + if (ip_route_output(&rt, dest->addr, 0, rtos, 0)) {
  895. + spin_unlock(&dest->dst_lock);
  896. + IP_VS_DBG_RL("ip_route_output error, "
  897. + "dest: %u.%u.%u.%u\n",
  898. + NIPQUAD(dest->addr));
  899. + return NULL;
  900. + }
  901. + __ip_vs_dst_set(dest, rtos, dst_clone(&rt->u.dst));
  902. + IP_VS_DBG(10, "new dst %u.%u.%u.%u, refcnt=%d, rtos=%X\n",
  903. + NIPQUAD(dest->addr),
  904. + atomic_read(&rt->u.dst.__refcnt), rtos);
  905. + }
  906. + spin_unlock(&dest->dst_lock);
  907. + } else {
  908. + if (ip_route_output(&rt, cp->daddr, 0, rtos, 0)) {
  909. + IP_VS_DBG_RL("ip_route_output error, dest: "
  910. + "%u.%u.%u.%u\n", NIPQUAD(cp->daddr));
  911. + return NULL;
  912. + }
  913. + }
  914. +
  915. + return rt;
  916. +}
  917. +
  918. +static inline u16 ip_vs_check_diff(u32 old, u32 new, u16 oldsum)
  919. +{
  920. + u32 diff[2] = { old, new };
  921. +
  922. + return csum_fold(csum_partial((char *) diff, sizeof(diff),
  923. + oldsum ^ 0xFFFF));
  924. +}
  925. +
  926. +static inline void ip_vs_fast_check_update(union ip_vs_tphdr *h,
  927. + u32 oldip, u32 newip, u16 oldport, u16 newport, u8 protocol)
  928. +{
  929. + u16 *checkp;
  930. +
  931. + if (protocol == IPPROTO_TCP)
  932. + checkp = &h->th->check;
  933. + else
  934. + checkp = &h->uh->check;
  935. + *checkp = ip_vs_check_diff(~oldip, newip,
  936. + ip_vs_check_diff(oldport ^ 0xFFFF,
  937. + newport, *checkp));
  938. + if (!*checkp && protocol == IPPROTO_UDP)
  939. + *checkp = 0xFFFF;
  940. +}
  941. +
  942. +static inline int
  943. +ip_vs_skb_cow(struct sk_buff *skb, unsigned int headroom,
  944. + struct iphdr **iph_p, unsigned char **t_p)
  945. +{
  946. + int delta = (headroom > 16 ? headroom : 16) - skb_headroom(skb);
  947. +
  948. + if (delta < 0)
  949. + delta = 0;
  950. +
  951. + if (delta || skb_cloned(skb)) {
  952. + if (pskb_expand_head(skb, (delta+15)&~15, 0, GFP_ATOMIC))
  953. + return -ENOMEM;
  954. +
  955. + /* skb data changed, update pointers */
  956. + *iph_p = skb->nh.iph;
  957. + *t_p = (char*) (*iph_p) + (*iph_p)->ihl * 4;
  958. + }
  959. + return 0;
  960. +}
  961. +
  962. +#endif /* __KERNEL__ */
  963. +
  964. +#endif /* _IP_VS_H */