--- dserver-0.1/tcpcp3/src/libtcpcp/tcpcp.h 2009-12-15 14:17:57.000000000 +0100 +++ /usr/src/kernel-xos-2.6.27.24-4xos/include/linux/tcpcp.h 2010-01-07 15:03:00.000000000 +0100 @@ -1,79 +1,55 @@ /* - * tcpcp.h - TCP connection passing library high-level API - * - * This library is free software: you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation, either version 3 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this program. If not, see - * . + * linux/tcpcp.h - TCP connection passing, data structures and prototypes * * Written 2002 by Werner Almesberger - * Distributed under the LGPL. * - * Copyright (C) 2005-2006 NTT Corporation - * Portions Copyright (C) Vrije Universiteit, Amsterdam. 2009. + * Copyright (C) 2005 NTT Corporation */ +#ifndef _LINUX_TCPCP_H +#define _LINUX_TCPCP_H -#ifndef TCPCP_H -#define TCPCP_H - -#include -#include +#include -#ifdef __cplusplus -extern "C" { +#ifdef __KERNEL__ +#include +#include +#include +#include + +#ifdef CONFIG_TCPCP_DEBUG +#define TCPCP_DPRINTK(fmt, args...) printk(KERN_DEBUG "TCPCP3: %s: " fmt, __func__, ## args) +#else +#define TCPCP_DPRINTK(fmt, args...) #endif -#define TCPCP_RET_OK 0 -#define TCPCP_RET_NG -1 - -#define TCPCP_EXEC_ONE 0 -#define TCPCP_EXEC_ALL 1 - -enum tcpcp_sockopt { - TCPCP_MAKE_SI = 16, - TCPCP_MAKE_SI_ALL, - TCPCP_GET_SI, - TCPCP_STOP, - TCPCP_STOP_ALL, - TCPCP_CLOSE, - TCPCP_CLOSE_ALL, - TCPCP_SET_SI, - TCPCP_SET_SI_ALL, - TCPCP_START, - TCPCP_START_ALL, - TCPCP_GET_RES_SIZE, - TCPCP_GET_RES, -}; -/* ----- FD Result (FDR) Information (only "ALL") -------------------------- */ +#define TCPCP_MODULE_NAME "tcpcp" -struct tcpcp_fdr { - int fd; - int result; -}; +#define TCPCP_FLAG_MAKE_SI 0x01 +#define TCPCP_FLAG_STOP 0x02 +#define TCPCP_FLAG_CLOSE 0x04 +#define TCPCP_FLAG_SET_SI 0x08 +#define TCPCP_FLAG_START 0x10 +#define TCPCP_FLAG_FLUSH 0x20 +#define TCPCP_FLAG_ALL 0x80 -struct result_list { - unsigned int fd_all; /* total of fd that succeeds in processing */ - unsigned int fd_ng; /* Number of fd that fails in processing */ - struct tcpcp_fdr fdrs[0]; /* processing result pointer */ -}; +#define plugin_dummy() __asm__ __volatile__("nop\n\t" \ + "nop\n\t" \ + "nop\n\t" \ + "nop\n\t" \ + "nop\n\t" \ + "nop\n\t" \ + "nop\n\t" \ + "nop\n\t" \ + "nop\n\t" \ + "nop\n\t" \ + "nop\n\t" \ + "nop\n\t" \ + "nop\n\t" \ + "nop\n\t") -struct result { - unsigned int fd_all; /* total of fd that succeeds in processing */ - unsigned int fd_ng; /* Number of fd that fails in processing */ - unsigned int buf_size; - unsigned int fdrs_size; -}; +#endif /* __KERNEL__ */ /* ----- TCP Socket Informations (TCP-SIs) --------------------------------- */ @@ -89,8 +65,8 @@ uint8_t flags; /* TCP header flags */ uint8_t sacked; /* state flags for SACK/FACK */ uint8_t __pad2[2]; - uint16_t tso_segs; - uint16_t tso_size; + uint16_t gso_segs; + uint16_t gso_size; uint32_t seq; /* sequence number of first byte */ uint8_t data[0]; /* data, padded to multiple of 4 bytes */ }; @@ -104,8 +80,8 @@ * TCP-SI element: globally unique TCP connection ID **/ struct tcpcp_sie_id4 { - uint32_t ip_src; /* source IPv4 address */ - uint32_t ip_dst; /* destination IPv4 address */ + struct in_addr ip_src; /* source IPv4 address */ + struct in_addr ip_dst; /* destination IPv4 address */ }; struct tcpcp_sie_id6 { @@ -278,12 +254,11 @@ struct tcpcp_si_hdr si_hdr[0]; }; -/* ------------------------------------------------------------------------- */ -/* Convenience macros for tcpcp header fields. They do not cast the - * argument to a struct tcpcp_si_hdr so that the compiler can check the - * types! - */ + /** + * Convenience macros going from tcpcp_total_si_hdr (i.e., user + * interface object) to specific members. + */ #define tcpcp_hdr_ip6_src(__b) ((__b)->si_hdr->id.ip.v6.ip_src) #define tcpcp_hdr_ip6_dst(__b) ((__b)->si_hdr->id.ip.v6.ip_dst) #define tcpcp_hdr_ip4_src(__b) ((__b)->si_hdr->id.ip.v4.ip_src) @@ -295,38 +270,233 @@ #define tcpcp_hdr_var_snd_wnd(__b) ((__b)->si_hdr->vargen.snd_wnd) #define tcpcp_hdr_var_ts_gen(__b) ((__b)->si_hdr->vargen.ts_gen) #define tcpcp_hdr_var_ts_recent(__b) ((__b)->si_hdr->vargen.ts_recent) -#define tcpcp_hdr_isvalid(__b) \ - ( (sizeof(struct tcpcp_si_hdr) <= (__b)->total_si_length) \ - && (1 <= (__b)->si_cnt) ) + + +/* ----- FD Result (FDR) Information (only "ALL") -------------------------- */ + +struct fdr { + int fd; + int result; +}; + +struct result_list { + unsigned int fd_all; /* total of fd that succeeds in processing */ + unsigned int fd_ng; /* Number of fd that fails in processing */ + struct fdr fdrs[0]; /* processing result pointer */ +}; + +struct result { + unsigned int fd_all; /* total of fd that succeeds in processing */ + unsigned int fd_ng; /* Number of fd that fails in processing */ + unsigned int buf_size; + unsigned int fdrs_size; +}; + + +/* ---- Process, Request, TCP-SIs and FDR Info. Entry ---------------------- */ + +#ifdef __KERNEL__ + +/** + * TCP-SI buffer (It's used at setting TCP-SI) + **/ +struct tcpcp_si_skb_buf { + unsigned int max_buf_len; + unsigned int buf_len; + unsigned int skb_cnt; + char *si_skb; +}; + +struct tcpcp_si_buf { + struct tcpcp_si_hdr si_hdr; /* TCP-SI header */ + struct tcpcp_si_skb_buf snd_buf; + struct tcpcp_si_skb_buf rcv_buf; +}; + +#define TCPCP_PAGE_NUM_SET_SI 24 +#define TCPCP_SI_SKB_BUF_SIZE PAGE_SIZE * TCPCP_PAGE_NUM_SET_SI + +/** + * common entry (It's used at making TCP-SIs or FDR Info.) + **/ +struct tcpcp_com_entry { + struct tcpcp_com_entry *next; /* next entry */ + unsigned int max_data_len; + unsigned int data_len; /* length of data */ + char data[0]; +}; + +#define TCPCP_PAGE_NUM_MAKE_SI_ONE 3 +#define TCPCP_COM_ENTRY_SIZE_FOR_ONE PAGE_SIZE * TCPCP_PAGE_NUM_MAKE_SI_ONE +#define TCPCP_COM_ENTRY_SIZE_FOR_ALL (PAGE_SIZE << 5) /* MAX_GFP_ORDER */ + +/** + * Request Entry + **/ +struct tcpcp_req_entry { + struct list_head node; + struct list_head timer_node; + uint32_t fd; + struct sock *sk; + pid_t pid; + unsigned char flag; + char dummy[3]; + unsigned int timeout; + struct result res; + struct tcpcp_com_entry *s_entry; /* TCP-SIs Entry */ + struct tcpcp_com_entry *f_entry; /* FDR Entry (only "ALL") */ + struct tcpcp_proc_entry *p_entry; /* parent Process Entry */ +}; + +#define TCPCP_WATCH_INTERVAL HZ +#define TCPCP_RETRY_WATCH_INTERVAL TCPCP_WATCH_INTERVAL / 10 +#define TCPCP_REQ_ENTRY_TIMEOUT HZ * 10 + +/** + * Process Entry + **/ +struct tcpcp_proc_entry { + struct list_head node; + gid_t tgid; + unsigned char flag; + char dummy[3]; + struct list_head r_list_head; /* Request List */ +}; + +/** + * Process List or Timeout List + **/ +struct tcpcp_list { + struct list_head head; + rwlock_t lock; +}; +#endif /* __KERNEL__ */ + + +/* ---- -------------------------------------------------------------------- */ + +#define TCPCP_RET_OK 0 +#define TCPCP_RET_NG -1 + +#define TCPCP_EXEC_ONE 0 +#define TCPCP_EXEC_ALL 1 + +#define TCPCP_SET_FLAG_OFF 0 +#define TCPCP_SET_FLAG_ON 1 int tcpcp_get_si(int fd, int flag, void **bufptr, unsigned int *size, - struct result_list **reslst); + struct result_list **reslst); int tcpcp_stop(int fd, int flag, struct result_list **reslst); int tcpcp_close(int fd, struct result_list **reslst); int tcpcp_set_si(int fd, int flag, void *bufptr, unsigned int size, - struct result_list **reslst); + struct result_list **reslst); int tcpcp_start(int fd, int flag, struct result_list **reslst); - int tcpcp_flush(int fd, struct timespec *timeout); -void tcpcp_free_results(struct result_list *reslst); -void tcpcp_free_si(void *bufptr, unsigned int size); +int tcpcp_flush(int fd, struct timespec *timeout); -#define plugin_dummy() __asm__ __volatile__("nop\n\t" \ - "nop\n\t" \ - "nop\n\t" \ - "nop\n\t" \ - "nop\n\t" \ - "nop\n\t" \ - "nop\n\t" \ - "nop\n\t" \ - "nop\n\t" \ - "nop\n\t" \ - "nop\n\t" \ - "nop\n\t" \ - "nop\n\t" \ - "nop\n\t") +/* + * Buffers are in sequence, first all send, then all out-of-order buffers. + * Buffers must not overlap, and may not contain any extraneous data (e.g. + * ack'ed bytes, or such). snd_nxt does not have to be at a buffer boundary. + */ + + +#ifdef __KERNEL__ + +#if defined(CONFIG_TCPCP) || defined(CONFIG_TCPCP_MODULE) -#ifdef __cplusplus - } +#include +#include +#include +#include + +typedef struct tcpcp_config_st { + /** + * Hooks + **/ + int (*tcpcp_com_ope_hook)(struct sock *sk, int optname, + struct result *user_res); + int (*tcpcp_get_si_hook)(struct sock *sk, + struct tcpcp_total_si_hdr *user_si, + unsigned int *user_size); + int (*tcpcp_get_res_hook)(struct sock *sk, struct fdr *user_fdrs, + unsigned int *user_size); + int (*tcpcp_set_si_hook)(struct sock *sk, int optname, + const struct tcpcp_total_si_hdr *user_si, + unsigned int size); + void (*tcpcp_close_hook)(struct sock *sk); + + int (*tcpcp_flush_hook)(struct sock *sk, struct timespec *user_timeout); + + /** + * Socket operations + **/ +#ifdef CONFIG_TCP_MD5SIG + struct tcp_sock_af_ops tcpcp_sock_ipv4_specific; + const struct tcp_sock_af_ops *orig_sock_ipv4_specific_ptr; +#endif /* CONFIG_TCP_MD5SIG */ + struct inet_connection_sock_af_ops tcpcp_ipv4_specific; + const struct inet_connection_sock_af_ops *orig_ipv4_specific_ptr; +#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) + struct inet_connection_sock_af_ops tcpcp_ipv6_specific; + struct inet_connection_sock_af_ops tcpcp_ipv6_mapped; + const struct inet_connection_sock_af_ops *orig_ipv6_specific_ptr; + const struct inet_connection_sock_af_ops *orig_ipv6_mapped_ptr; +#ifdef CONFIG_TCP_MD5SIG + struct tcp_sock_af_ops tcpcp_sock_ipv6_mapped_specific; + const struct tcp_sock_af_ops *orig_sock_ipv6_mapped_specific_ptr; + struct tcp_sock_af_ops tcpcp_sock_ipv6_specific; + const struct tcp_sock_af_ops *orig_sock_ipv6_specific_ptr; +#endif /* CONFIG_TCP_MD5SIG */ +#endif /* CONFIG_IPV6 || CONFIG_IPV6_MODULE */ +} tcpcp_config_t; + +/* timeout of polling for tcpcp_flush() */ +#define TCPCP_FLUSH_POLL_TIMEOUT_USECS 100 + + /** + * Get access to global tcpcp config options + */ +tcpcp_config_t *tcpcp_get_config(void); + + /* Initialize IPv4 settings */ +void tcpcp_v4_init(void); +#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) + /* Initialize IPv6 settings */ +void tcpcp_v6_init(void); #endif -#endif /* TCPCP_H */ +extern struct sk_filter drop_all; + +int tcpcp_discard_xmit(struct sk_buff *skb, int ipfragok); +void tcpcp_fix_seq(struct sock *sk, __u32 seq, __u32 ackseq); +void tcpcp_fix_ts(struct sock *sk, __u32 ack_tsecr); + +/** + * Hook call functions + **/ +int tcpcp_call_com_ope_hook(struct sock *sk, int optname, + struct result *user_res); +int tcpcp_call_set_si_hook(struct sock *sk, int optname, + const struct tcpcp_total_si_hdr *user_si, + unsigned int size); +int tcpcp_call_get_si_hook(struct sock *sk, struct tcpcp_total_si_hdr *user_si, + unsigned int *user_size); +int tcpcp_call_get_res_hook(struct sock *sk, struct fdr *user_fdrs, + unsigned int *user_size); +void tcpcp_call_close_hook(struct sock *sk); +int tcpcp_call_flush_hook(struct sock *sk, struct timespec *user_timeout); + +#else /* defined(CONFIG_TCPCP) || defined(CONFIG_TCPCP_MODULE) */ + +#define tcpcp_call_com_ope_hook(sk, optname, val) (-ENOPROTOOPT) +#define tcpcp_call_set_si_hook(sk, optname, val, size) (-ENOPROTOOPT) +#define tcpcp_call_get_si_hook(sk, val, size) (-ENOPROTOOPT) +#define tcpcp_call_get_res_hook(sk, val, size) (-ENOPROTOOPT) +#define tcpcp_call_close_hook(sk) (-ENOPROTOOPT) +#define tcpcp_call_flush_hook(sk, val) (-ENOPROTOOPT) + +#endif /* !defined(CONFIG_TCPCP) && !defined(CONFIG_TCPCP_MODULE) */ + +#endif /* __KERNEL__ */ + +#endif /* _LINUX_TCPCP_H */