reject: reindent and code cleaning

Reindent file and use some switch instead of if else if.
pull/572/merge
Eric Leblond 12 years ago committed by Victor Julien
parent 6cf7da30e2
commit 9bbd2a103d

@ -57,8 +57,7 @@ extern int sc_set_caps;
#include <libnet.h> #include <libnet.h>
typedef struct Libnet11Packet_ typedef struct Libnet11Packet_ {
{
uint32_t ack, seq; uint32_t ack, seq;
uint16_t window, dsize; uint16_t window, dsize;
uint8_t ttl; uint8_t ttl;
@ -71,7 +70,8 @@ typedef struct Libnet11Packet_
size_t len; size_t len;
} Libnet11Packet; } Libnet11Packet;
int RejectSendLibnet11L3IPv4TCP(ThreadVars *tv, Packet *p, void *data, int dir) { int RejectSendLibnet11L3IPv4TCP(ThreadVars *tv, Packet *p, void *data, int dir)
{
Libnet11Packet lpacket; Libnet11Packet lpacket;
libnet_t *c; /* libnet context */ libnet_t *c; /* libnet context */
@ -84,8 +84,7 @@ int RejectSendLibnet11L3IPv4TCP(ThreadVars *tv, Packet *p, void *data, int dir)
lpacket.flow = 0; lpacket.flow = 0;
lpacket.class = 0; lpacket.class = 0;
if ((c = libnet_init (LIBNET_RAW4, NULL, ebuf)) == NULL) if ((c = libnet_init(LIBNET_RAW4, NULL, ebuf)) == NULL) {
{
SCLogError(SC_ERR_LIBNET_INIT,"libnet_inint failed: %s", ebuf); SCLogError(SC_ERR_LIBNET_INIT,"libnet_inint failed: %s", ebuf);
return 1; return 1;
} }
@ -96,7 +95,8 @@ int RejectSendLibnet11L3IPv4TCP(ThreadVars *tv, Packet *p, void *data, int dir)
/* save payload len */ /* save payload len */
lpacket.dsize = p->payload_len; lpacket.dsize = p->payload_len;
if (dir == REJECT_DIR_SRC) { switch (dir) {
case REJECT_DIR_SRC:
SCLogDebug("sending a tcp reset to src"); SCLogDebug("sending a tcp reset to src");
lpacket.seq = TCP_GET_ACK(p); lpacket.seq = TCP_GET_ACK(p);
lpacket.ack = TCP_GET_SEQ(p) + lpacket.dsize; lpacket.ack = TCP_GET_SEQ(p) + lpacket.dsize;
@ -106,8 +106,8 @@ int RejectSendLibnet11L3IPv4TCP(ThreadVars *tv, Packet *p, void *data, int dir)
lpacket.src4 = GET_IPV4_DST_ADDR_U32(p); lpacket.src4 = GET_IPV4_DST_ADDR_U32(p);
lpacket.dst4 = GET_IPV4_SRC_ADDR_U32(p); lpacket.dst4 = GET_IPV4_SRC_ADDR_U32(p);
} break;
else if (dir == REJECT_DIR_DST) { case REJECT_DIR_DST:
SCLogDebug("sending a tcp reset to dst"); SCLogDebug("sending a tcp reset to dst");
lpacket.seq = TCP_GET_SEQ(p); lpacket.seq = TCP_GET_SEQ(p);
lpacket.ack = TCP_GET_ACK(p); lpacket.ack = TCP_GET_ACK(p);
@ -117,9 +117,10 @@ int RejectSendLibnet11L3IPv4TCP(ThreadVars *tv, Packet *p, void *data, int dir)
lpacket.src4 = GET_IPV4_SRC_ADDR_U32(p); lpacket.src4 = GET_IPV4_SRC_ADDR_U32(p);
lpacket.dst4 = GET_IPV4_DST_ADDR_U32(p); lpacket.dst4 = GET_IPV4_DST_ADDR_U32(p);
break;
} else { default:
SCLogError(SC_ERR_LIBNET_INVALID_DIR,"reset not src or dst returning"); SCLogError(SC_ERR_LIBNET_INVALID_DIR,
"reset not src or dst returning");
return 1; return 1;
} }
@ -179,7 +180,8 @@ cleanup:
return 0; return 0;
} }
int RejectSendLibnet11L3IPv4ICMP(ThreadVars *tv, Packet *p, void *data, int dir) { int RejectSendLibnet11L3IPv4ICMP(ThreadVars *tv, Packet *p, void *data, int dir)
{
//printf("going to send a ICMP host unreachable\n"); //printf("going to send a ICMP host unreachable\n");
Libnet11Packet lpacket; Libnet11Packet lpacket;
libnet_t *c; /* libnet context */ libnet_t *c; /* libnet context */
@ -198,16 +200,18 @@ int RejectSendLibnet11L3IPv4ICMP(ThreadVars *tv, Packet *p, void *data, int dir)
return 1; return 1;
} }
if (dir == REJECT_DIR_SRC) { switch (dir) {
case REJECT_DIR_SRC:
lpacket.src4 = GET_IPV4_DST_ADDR_U32(p); lpacket.src4 = GET_IPV4_DST_ADDR_U32(p);
lpacket.dst4 = GET_IPV4_SRC_ADDR_U32(p); lpacket.dst4 = GET_IPV4_SRC_ADDR_U32(p);
} break;
else if (dir == REJECT_DIR_DST) { case REJECT_DIR_DST:
lpacket.src4 = GET_IPV4_SRC_ADDR_U32(p); lpacket.src4 = GET_IPV4_SRC_ADDR_U32(p);
lpacket.dst4 = GET_IPV4_DST_ADDR_U32(p); lpacket.dst4 = GET_IPV4_DST_ADDR_U32(p);
break;
} else { default:
SCLogError(SC_ERR_LIBNET_INVALID_DIR,"reset not src or dst returning"); SCLogError(SC_ERR_LIBNET_INVALID_DIR,
"reset not src or dst returning");
return 1; return 1;
} }
@ -261,13 +265,19 @@ cleanup:
#else #else
int RejectSendLibnet11L3IPv4TCP(ThreadVars *tv, Packet *p, void *data, int dir) { int RejectSendLibnet11L3IPv4TCP(ThreadVars *tv, Packet *p, void *data, int dir)
SCLogError(SC_ERR_LIBNET_NOT_ENABLED,"Libnet based rejects are disabled. Usually this means that you don't have libnet installed, or configure couldn't find it."); {
SCLogError(SC_ERR_LIBNET_NOT_ENABLED, "Libnet based rejects are disabled."
"Usually this means that you don't have libnet installed,"
" or configure couldn't find it.");
return 0; return 0;
} }
int RejectSendLibnet11L3IPv4ICMP(ThreadVars *tv, Packet *p, void *data, int dir) { int RejectSendLibnet11L3IPv4ICMP(ThreadVars *tv, Packet *p, void *data, int dir)
SCLogError(SC_ERR_LIBNET_NOT_ENABLED,"Libnet based rejects are disabled. Usually this means that you don't have libnet installed, or configure couldn't find it."); {
SCLogError(SC_ERR_LIBNET_NOT_ENABLED, "Libnet based rejects are disabled."
"Usually this means that you don't have libnet installed,"
" or configure couldn't find it.");
return 0; return 0;
} }

Loading…
Cancel
Save