]> mj.ucw.cz Git - netgrind.git/blob - netgrind/netgrind.h
Added content-type to HTTP dump.
[netgrind.git] / netgrind / netgrind.h
1 /*
2  *      Netgrind -- The Network Traffic Analyser
3  *
4  *      (c) 2003 Martin Mares <mj@ucw.cz>
5  *
6  *      This software may be freely distributed and used according to the terms
7  *      of the GNU General Public License.
8  */
9
10 #define IPQUAD(x) ((byte*)&(x))[0], ((byte*)&(x))[1], ((byte*)&(x))[2], ((byte*)&(x))[3]
11
12 /* link.c */
13
14 extern struct pkt_stats stat_link_dwarf, stat_link_in, stat_link_unknown, stat_link_arp;
15
16 void link_eth_got_packet(struct pkt *p);
17
18 /* ip.c */
19
20 extern struct pkt_stats stat_ip_in, stat_ip_invalid, stat_ip_uninteresting, stat_ip_fragmented, stat_ip_badsum;
21
22 uns tcpip_calc_checksum(void *data, uns len, uns csum);
23 uns tcpip_verify_checksum(uns csum);
24 void ip_got_packet(struct pkt *p);
25
26 /* tcp.c */
27
28 extern struct pkt_stats stat_tcp_in, stat_tcp_invalid, stat_tcp_badsum, stat_tcp_unmatched,
29   stat_tcp_on_closed, stat_tcp_bad_state;
30 extern uns cnt_tcp_flows, cnt_tcp_causes[], tcp_num_flows, tcp_max_flows;
31
32 /* config switches */
33 extern uns tcp_arrival_times;
34 extern uns tcp_wait_for_ack;
35
36 struct pipe {
37   list queue;                           /* incoming packets */
38   u32 last_acked_seq;                   /* last sequence number for which I sent ACK */
39   u32 syn_or_fin_seq;                   /* sequence number of SYN/FIN I sent */
40   u32 queue_start_seq;                  /* sequence number expected at the start of the queue */
41   enum {                                /* very simplified TCP state machine */
42     FLOW_IDLE,
43     FLOW_SYN_SENT,                      /* sent SYN, waiting for SYN ACK */
44     FLOW_SYN_SENT_ACK,                  /* sent SYN ACK, waiting for first ACK */
45     FLOW_ESTABLISHED,                   /* established state including waiting for ACK of SYN ACK */
46     FLOW_FIN_SENT,                      /* sent FIN, waiting for its ACK */
47     FLOW_FINISHED                       /* closed, ignoring further packets */
48   } state;
49   struct pkt_stats stat;
50 };
51
52 struct flow {
53   struct flow *hash_next;
54   u32 saddr, daddr, sport, dport;
55   u32 timeout;
56   uns heap_pos;
57   struct appl_hooks *appl;
58   void *appl_data;
59   struct pipe pipe[2];
60   struct pkt_stats stat_raw;
61   uns cnt_unexpected;
62 };
63
64 enum close_cause {
65   CAUSE_CLOSE,
66   CAUSE_RESET,
67   CAUSE_TIMEOUT,
68   CAUSE_DOOMSDAY,
69   CAUSE_CORRUPT,
70   CAUSE_MAX
71 };
72
73 extern byte *flow_state_names[];
74 extern byte *flow_cause_names[], *flow_cause_names_short[];
75
76 struct appl_hooks {
77   void (*open)(struct flow *f, u64 when);
78   void (*input)(struct flow *f, int dir, struct pkt *p); /* dir0 = sent by initiator, pkt_len(p)==0 for close */
79   void (*close)(struct flow *f, int cause, u64 when);
80 };
81
82 struct iphdr;
83
84 void tcp_init(void);
85 void tcp_cleanup(u64 timestamp);
86 void tcp_got_packet(struct iphdr *iph, struct pkt *p);
87
88 extern struct appl_hooks *tcp_default_appl;
89
90 /* save.c */
91
92 extern struct appl_hooks appl_sink, appl_save, appl_asave, appl_summary;
93 extern uns asave_width;
94 extern byte *save_dir;
95
96 void sink_open(struct flow *f, u64 when);
97 void sink_close(struct flow *f, int cause, u64 when);
98 void sink_input(struct flow *f, int dir, struct pkt *p);
99
100 #define TIMESTAMP_LEN 32
101 void format_timestamp(byte *buf, u64 time);
102
103 /* http.c */
104
105 extern struct appl_hooks appl_http;
106
107 /* histogram.c */
108
109 void histogram_init(byte *name);
110 void histogram_add_stat(byte *name, struct pkt_stats *stat);
111 void histogram_add_int(byte *name, int *var);
112 void histogram_step(uns time);
113 void histogram_cleanup(void);