PERFORCE change 143795 for review
Rui Paulo
rpaulo at FreeBSD.org
Thu Jun 19 23:51:25 UTC 2008
http://perforce.freebsd.org/chv.cgi?CH=143795
Change 143795 by rpaulo at rpaulo_epsilon on 2008/06/19 23:50:47
Rename variables to more sensible names.
Affected files ...
.. //depot/projects/soc2008/rpaulo-tcpad/handler.c#10 edit
.. //depot/projects/soc2008/rpaulo-tcpad/tcpad.h#7 edit
Differences ...
==== //depot/projects/soc2008/rpaulo-tcpad/handler.c#10 (text+ko) ====
@@ -23,7 +23,7 @@
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
- * $P4: //depot/projects/soc2008/rpaulo-tcpad/handler.c#9 $
+ * $P4: //depot/projects/soc2008/rpaulo-tcpad/handler.c#10 $
*/
#include <stdio.h>
@@ -47,9 +47,9 @@
#include "debug.h"
-static conn_t * find_conn(struct in_addr ipsrc, struct in_addr ipdst,
+static struct tcpc *find_conn(struct in_addr ipsrc, struct in_addr ipdst,
unsigned short sport, unsigned short dport);
-static void print_packet(const unsigned char *bytes, const int linkhlen);
+static void print_packet(const unsigned char *bytes, const int linkhlen);
void
tcpad_pcaphandler(unsigned char *user, const struct pcap_pkthdr *ph,
@@ -58,8 +58,8 @@
const struct ip *ip;
const struct tcphdr *tcp;
int linkhlen;
- conn_t *cp;
- conn_t *rcp;
+ struct tcpc *cp;
+ struct tcpc *rcp;
linkhlen = (int)*user;
@@ -80,7 +80,7 @@
free(cp);
}
cp = malloc(sizeof(*cp));
- cp->tcpstate = TCPS_SYN_SENT;
+ cp->t_state = TCPS_SYN_SENT;
cp->dport = tcp->th_dport;
cp->sport = tcp->th_sport;
cp->isv6 = 0;
@@ -89,7 +89,7 @@
DPRINTF("tracking (syn) connection between %s and ",
inet_ntoa(cp->sv4addr));
DPRINTF("%s\n",inet_ntoa(cp->dv4addr));
- LIST_INSERT_HEAD(&chead, cp, entries);
+ LIST_INSERT_HEAD(&tcpchead, cp, entries);
print_packet(bytes, linkhlen);
/*
@@ -112,7 +112,7 @@
free(cp);
}
cp = malloc(sizeof(*cp));
- cp->tcpstate = TCPS_SYN_RECEIVED;
+ cp->t_state = TCPS_SYN_RECEIVED;
cp->dport = tcp->th_dport;
cp->sport = tcp->th_sport;
cp->isv6 = 0;
@@ -121,7 +121,7 @@
DPRINTF("tracking (syn/ack) connection between %s and ",
inet_ntoa(cp->sv4addr));
DPRINTF("%s\n",inet_ntoa(cp->dv4addr));
- LIST_INSERT_HEAD(&chead, cp, entries);
+ LIST_INSERT_HEAD(&tcpchead, cp, entries);
print_packet(bytes, linkhlen);
/* rcp->pktshead should have been already malloc'ed and
@@ -133,22 +133,22 @@
return;
dumper_addpkt(cp->pktshead, ph, bytes);
- if (cp->tcpstate == TCPS_SYN_SENT ||
- cp->tcpstate == TCPS_SYN_RECEIVED) {
- cp->tcpstate = TCPS_ESTABLISHED;
- rcp->tcpstate = TCPS_ESTABLISHED;
+ if (cp->t_state == TCPS_SYN_SENT ||
+ cp->t_state == TCPS_SYN_RECEIVED) {
+ cp->t_state = TCPS_ESTABLISHED;
+ rcp->t_state = TCPS_ESTABLISHED;
DPRINTF("established\n");
print_packet(bytes, linkhlen);
}
- if (cp->tcpstate == TCPS_ESTABLISHED &&
- rcp->tcpstate == TCPS_FIN_WAIT_1) {
+ if (cp->t_state == TCPS_ESTABLISHED &&
+ rcp->t_state == TCPS_FIN_WAIT_1) {
printf("first ack\n");
- cp->tcpstate = TCPS_CLOSE_WAIT;
- rcp->tcpstate = TCPS_FIN_WAIT_2;
+ cp->t_state = TCPS_CLOSE_WAIT;
+ rcp->t_state = TCPS_FIN_WAIT_2;
}
- if (cp->tcpstate == TCPS_LAST_ACK ||
- cp->tcpstate == TCPS_CLOSING) {
- cp->tcpstate = TCPS_TIME_WAIT;
+ if (cp->t_state == TCPS_LAST_ACK ||
+ cp->t_state == TCPS_CLOSING) {
+ cp->t_state = TCPS_TIME_WAIT;
printf("connection down\n");
}
} else if ((tcp->th_flags & TH_FLAGS) == (TH_FIN|TH_ACK)) {
@@ -156,22 +156,22 @@
return;
dumper_addpkt(cp->pktshead, ph, bytes);
- if (cp->tcpstate == TCPS_ESTABLISHED) {
- cp->tcpstate = TCPS_FIN_WAIT_1;
+ if (cp->t_state == TCPS_ESTABLISHED) {
+ cp->t_state = TCPS_FIN_WAIT_1;
DPRINTF("fin_wait_1\n");
print_packet(bytes, linkhlen);
}
- if (cp->tcpstate == TCPS_CLOSE_WAIT &&
- rcp->tcpstate == TCPS_FIN_WAIT_2) {
+ if (cp->t_state == TCPS_CLOSE_WAIT &&
+ rcp->t_state == TCPS_FIN_WAIT_2) {
printf("last_ack\n");
- cp->tcpstate = TCPS_TIME_WAIT;
- rcp->tcpstate = TCPS_LAST_ACK;
+ cp->t_state = TCPS_TIME_WAIT;
+ rcp->t_state = TCPS_LAST_ACK;
}
- if (cp->tcpstate == TCPS_FIN_WAIT_1) {
- cp->tcpstate = TCPS_CLOSING;
+ if (cp->t_state == TCPS_FIN_WAIT_1) {
+ cp->t_state = TCPS_CLOSING;
}
} else if ((tcp->th_flags & TH_FLAGS) == (TH_RST|TH_ACK)) {
- if (rcp && rcp->tcpstate == TCPS_SYN_SENT) {
+ if (rcp && rcp->t_state == TCPS_SYN_SENT) {
DPRINTF("stopped tracking connection (rst) between"
" %s and ", inet_ntoa(rcp->sv4addr));
DPRINTF("%s\n",inet_ntoa(rcp->dv4addr));
@@ -182,13 +182,13 @@
}
}
-static conn_t *
+static struct tcpc *
find_conn(struct in_addr ipsrc, struct in_addr ipdst, unsigned short
sport, unsigned short dport)
{
- conn_t *cp;
+ struct tcpc *cp;
- LIST_FOREACH(cp, &chead, entries) {
+ LIST_FOREACH(cp, &tcpchead, entries) {
if (memcmp(&cp->sv4addr, &ipsrc, sizeof(struct in_addr)) == 0 &&
memcmp(&cp->dv4addr, &ipdst, sizeof(struct in_addr)) == 0 &&
cp->sport == sport && cp->dport == dport) {
==== //depot/projects/soc2008/rpaulo-tcpad/tcpad.h#7 (text+ko) ====
@@ -23,7 +23,7 @@
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
- * $P4: //depot/projects/soc2008/rpaulo-tcpad/tcpad.h#6 $
+ * $P4: //depot/projects/soc2008/rpaulo-tcpad/tcpad.h#7 $
*/
#ifndef _TCPAD_H_
@@ -33,17 +33,17 @@
pcap_t *p;
-typedef struct _conn_t {
- LIST_ENTRY(_conn_t) entries;
+struct tcpc {
+ LIST_ENTRY(tcpc) entries;
struct in_addr sv4addr;
struct in_addr dv4addr;
unsigned short dport;
unsigned short sport;
- int tcpstate; /* TCP FSM state */
+ int t_state; /* TCP FSM state */
int isv6;
struct dumppkth *pktshead;
-} conn_t;
+};
-LIST_HEAD(chead, _conn_t) chead;
+LIST_HEAD(tcpchead, tcpc) tcpchead;
#endif /* _TCPAD_H_ */
More information about the p4-projects
mailing list