00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef LIBINET_PKBUF_H_
00012 #define LIBINET_PKBUF_H_
00013
00014 extern int gl_buf_cpt;
00015 extern int gl_pkbuf_cpt;
00016 extern int gl_data_buf_cpt;
00017
00018 struct s_buf
00019 {
00020 int bf_ref;
00021 };
00022
00023 struct s_data_buf
00024 {
00025 off_t data_off;
00026 size_t data_size;
00027 struct s_buf *data_buf;
00028
00029
00030 struct s_data_buf *data_fnext;
00031 off_t data_foff;
00032 };
00033
00034 #define BF_DATA(bf, off) ((char *)bf + sizeof (struct s_buf) + off)
00035
00036 struct s_pkbuf
00037 {
00038 struct s_pkbuf *pk_fnext;
00039 TAILQ_ENTRY(s_pkbuf) pk_next;
00040
00041 size_t pk_size;
00042
00043 #define PK_INPUT(pk) (pk)->pk_info.pk_input_info
00044 #define PK_OUTPUT(pk) (pk)->pk_info.pk_output_info
00045
00046 #define PK_DA(pk) (pk)->pk_info.pk_da
00047 #define PK_SA(pk) (pk)->pk_info.pk_sa
00048
00049 int64_t pk_ar;
00050
00051 struct s_pk_info
00052 {
00053 struct sockaddr_in pk_da;
00054 struct sockaddr_in pk_sa;
00055
00056 struct s_input_info
00057 {
00058 struct s_iface *pk_iface;
00059 } pk_input_info;
00060
00061 struct s_output_info
00062 {
00063 struct s_route_entry *pk_route;
00064 } pk_output_info;
00065 } pk_info;
00066
00067 struct s_buf *pk_lh_buf;
00068 size_t pk_lh_size;
00069 union {
00070 struct s_ethernet_hdr *lh_ethernet;
00071 vaddr_t lh_addr;
00072 } pk_lh;
00073
00074 struct s_buf *pk_nh_buf;
00075 size_t pk_nh_size;
00076 int pk_nh_type;
00077 union {
00078 struct s_ip_hdr *nh_ip;
00079 struct s_arp_hdr *nh_arp;
00080 vaddr_t nh_addr;
00081 } pk_nh;
00082
00083 struct s_buf *pk_ph_buf;
00084 size_t pk_ph_size;
00085 int pk_ph_type;
00086 union {
00087 struct s_udp_hdr *ph_udp;
00088 struct s_icmp_hdr *ph_icmp;
00089 struct s_tcp_hdr *ph_tcp;
00090 vaddr_t ph_addr;
00091 } pk_ph;
00092
00093 size_t pk_data_size;
00094 struct s_data_buf *pk_data;
00095 };
00096
00097 TAILQ_HEAD(s_pkq, s_pkbuf);
00098
00099
00100 #define EXTRACT_LH 0
00101 #define EXTRACT_NH 1
00102 #define EXTRACT_PH 2
00103
00104
00105 #define INCLUDE_DATA (1<<0)
00106 #define INCLUDE_PH (1<<1)
00107 #define INCLUDE_NH (1<<2)
00108 #define INCLUDE_LH (1<<3)
00109 #define INCLUDE_HDRS (INCLUDE_LH | INCLUDE_NH | INCLUDE_PH)
00110 #define INCLUDE_ALL (INCLUDE_DATA | INCLUDE_HDRS)
00111
00112
00113
00114 struct s_data_buf *data_buf_alloc2(size_t buf_size);
00115 struct s_data_buf *data_buf_alloc(struct s_buf *buf, off_t buf_off, size_t buf_size);
00116 struct s_data_buf *data_buf_clone(struct s_data_buf *data_buf);
00117 void data_buf_free(struct s_data_buf *data_buf);
00118 struct s_buf *buf_alloc(size_t size);
00119 struct s_pkbuf *pkbuf_alloc(size_t size);
00120 struct s_pkbuf *pkbuf_clone(struct s_pkbuf *pkbuf);
00121 char *pkbuf_extract(struct s_pkbuf *pk, int type, size_t size);
00122 char *pkbuf_extand(struct s_pkbuf *pk, int type, size_t extsize);
00123 ssize_t data_buf_write(struct s_data_buf *data_buf, pid_t owner, off_t offset, vaddr_t ubuf, size_t usize);
00124 ssize_t pkbuf_write(struct s_pkbuf *pkbuf, pid_t owner, off_t offset, int flags, vaddr_t ubuf, size_t usize);
00125 void buf_free(struct s_buf *buf);
00126 void pkbuf_free(struct s_pkbuf *pk);
00127
00128 u_int16_t pkbuf_cksum(struct s_pkbuf *pk, int flags, u_int8_t *phdr, size_t phdr_size);
00129 #endif