Commit f71cb8f4 authored by Florian Westphal's avatar Florian Westphal

netfilter: conntrack: sctp: use nf log infrastructure for invalid packets

The conntrack logging facilities include useful info such as in/out
interface names and packet headers.

Use those in more places instead of pr_debug calls.
Furthermore, several pr_debug calls can be removed, they are useless
on production machines due to the sheer volume of log messages.
Signed-off-by: default avatarFlorian Westphal <fw@strlen.de>
parent c4791b31
...@@ -168,7 +168,8 @@ for ((offset) = (dataoff) + sizeof(struct sctphdr), (count) = 0; \ ...@@ -168,7 +168,8 @@ for ((offset) = (dataoff) + sizeof(struct sctphdr), (count) = 0; \
static int do_basic_checks(struct nf_conn *ct, static int do_basic_checks(struct nf_conn *ct,
const struct sk_buff *skb, const struct sk_buff *skb,
unsigned int dataoff, unsigned int dataoff,
unsigned long *map) unsigned long *map,
const struct nf_hook_state *state)
{ {
u_int32_t offset, count; u_int32_t offset, count;
struct sctp_chunkhdr _sch, *sch; struct sctp_chunkhdr _sch, *sch;
...@@ -177,8 +178,6 @@ static int do_basic_checks(struct nf_conn *ct, ...@@ -177,8 +178,6 @@ static int do_basic_checks(struct nf_conn *ct,
flag = 0; flag = 0;
for_each_sctp_chunk (skb, sch, _sch, offset, dataoff, count) { for_each_sctp_chunk (skb, sch, _sch, offset, dataoff, count) {
pr_debug("Chunk Num: %d Type: %d\n", count, sch->type);
if (sch->type == SCTP_CID_INIT || if (sch->type == SCTP_CID_INIT ||
sch->type == SCTP_CID_INIT_ACK || sch->type == SCTP_CID_INIT_ACK ||
sch->type == SCTP_CID_SHUTDOWN_COMPLETE) sch->type == SCTP_CID_SHUTDOWN_COMPLETE)
...@@ -193,7 +192,9 @@ static int do_basic_checks(struct nf_conn *ct, ...@@ -193,7 +192,9 @@ static int do_basic_checks(struct nf_conn *ct,
sch->type == SCTP_CID_COOKIE_ECHO || sch->type == SCTP_CID_COOKIE_ECHO ||
flag) && flag) &&
count != 0) || !sch->length) { count != 0) || !sch->length) {
pr_debug("Basic checks failed\n"); nf_ct_l4proto_log_invalid(skb, ct, state,
"%s failed. chunk num %d, type %d, len %d flag %d\n",
__func__, count, sch->type, sch->length, flag);
return 1; return 1;
} }
...@@ -201,7 +202,6 @@ static int do_basic_checks(struct nf_conn *ct, ...@@ -201,7 +202,6 @@ static int do_basic_checks(struct nf_conn *ct,
set_bit(sch->type, map); set_bit(sch->type, map);
} }
pr_debug("Basic checks passed\n");
return count == 0; return count == 0;
} }
...@@ -211,69 +211,51 @@ static int sctp_new_state(enum ip_conntrack_dir dir, ...@@ -211,69 +211,51 @@ static int sctp_new_state(enum ip_conntrack_dir dir,
{ {
int i; int i;
pr_debug("Chunk type: %d\n", chunk_type);
switch (chunk_type) { switch (chunk_type) {
case SCTP_CID_INIT: case SCTP_CID_INIT:
pr_debug("SCTP_CID_INIT\n");
i = 0; i = 0;
break; break;
case SCTP_CID_INIT_ACK: case SCTP_CID_INIT_ACK:
pr_debug("SCTP_CID_INIT_ACK\n");
i = 1; i = 1;
break; break;
case SCTP_CID_ABORT: case SCTP_CID_ABORT:
pr_debug("SCTP_CID_ABORT\n");
i = 2; i = 2;
break; break;
case SCTP_CID_SHUTDOWN: case SCTP_CID_SHUTDOWN:
pr_debug("SCTP_CID_SHUTDOWN\n");
i = 3; i = 3;
break; break;
case SCTP_CID_SHUTDOWN_ACK: case SCTP_CID_SHUTDOWN_ACK:
pr_debug("SCTP_CID_SHUTDOWN_ACK\n");
i = 4; i = 4;
break; break;
case SCTP_CID_ERROR: case SCTP_CID_ERROR:
pr_debug("SCTP_CID_ERROR\n");
i = 5; i = 5;
break; break;
case SCTP_CID_COOKIE_ECHO: case SCTP_CID_COOKIE_ECHO:
pr_debug("SCTP_CID_COOKIE_ECHO\n");
i = 6; i = 6;
break; break;
case SCTP_CID_COOKIE_ACK: case SCTP_CID_COOKIE_ACK:
pr_debug("SCTP_CID_COOKIE_ACK\n");
i = 7; i = 7;
break; break;
case SCTP_CID_SHUTDOWN_COMPLETE: case SCTP_CID_SHUTDOWN_COMPLETE:
pr_debug("SCTP_CID_SHUTDOWN_COMPLETE\n");
i = 8; i = 8;
break; break;
case SCTP_CID_HEARTBEAT: case SCTP_CID_HEARTBEAT:
pr_debug("SCTP_CID_HEARTBEAT");
i = 9; i = 9;
break; break;
case SCTP_CID_HEARTBEAT_ACK: case SCTP_CID_HEARTBEAT_ACK:
pr_debug("SCTP_CID_HEARTBEAT_ACK");
i = 10; i = 10;
break; break;
case SCTP_CID_DATA: case SCTP_CID_DATA:
case SCTP_CID_SACK: case SCTP_CID_SACK:
pr_debug("SCTP_CID_DATA/SACK");
i = 11; i = 11;
break; break;
default: default:
/* Other chunks like DATA or SACK do not change the state */ /* Other chunks like DATA or SACK do not change the state */
pr_debug("Unknown chunk type, Will stay in %s\n", pr_debug("Unknown chunk type %d, Will stay in %s\n",
sctp_conntrack_names[cur_state]); chunk_type, sctp_conntrack_names[cur_state]);
return cur_state; return cur_state;
} }
pr_debug("dir: %d cur_state: %s chunk_type: %d new_state: %s\n",
dir, sctp_conntrack_names[cur_state], chunk_type,
sctp_conntrack_names[sctp_conntracks[dir][i][cur_state]]);
return sctp_conntracks[dir][i][cur_state]; return sctp_conntracks[dir][i][cur_state];
} }
...@@ -392,7 +374,7 @@ int nf_conntrack_sctp_packet(struct nf_conn *ct, ...@@ -392,7 +374,7 @@ int nf_conntrack_sctp_packet(struct nf_conn *ct,
if (sh == NULL) if (sh == NULL)
goto out; goto out;
if (do_basic_checks(ct, skb, dataoff, map) != 0) if (do_basic_checks(ct, skb, dataoff, map, state) != 0)
goto out; goto out;
if (!nf_ct_is_confirmed(ct)) { if (!nf_ct_is_confirmed(ct)) {
...@@ -414,7 +396,9 @@ int nf_conntrack_sctp_packet(struct nf_conn *ct, ...@@ -414,7 +396,9 @@ int nf_conntrack_sctp_packet(struct nf_conn *ct,
!test_bit(SCTP_CID_HEARTBEAT, map) && !test_bit(SCTP_CID_HEARTBEAT, map) &&
!test_bit(SCTP_CID_HEARTBEAT_ACK, map) && !test_bit(SCTP_CID_HEARTBEAT_ACK, map) &&
sh->vtag != ct->proto.sctp.vtag[dir]) { sh->vtag != ct->proto.sctp.vtag[dir]) {
pr_debug("Verification tag check failed\n"); nf_ct_l4proto_log_invalid(skb, ct, state,
"verification tag check failed %x vs %x for dir %d",
sh->vtag, ct->proto.sctp.vtag[dir], dir);
goto out; goto out;
} }
} }
...@@ -488,9 +472,10 @@ int nf_conntrack_sctp_packet(struct nf_conn *ct, ...@@ -488,9 +472,10 @@ int nf_conntrack_sctp_packet(struct nf_conn *ct,
/* Invalid */ /* Invalid */
if (new_state == SCTP_CONNTRACK_MAX) { if (new_state == SCTP_CONNTRACK_MAX) {
pr_debug("nf_conntrack_sctp: Invalid dir=%i ctype=%u " nf_ct_l4proto_log_invalid(skb, ct, state,
"conntrack=%u\n", "Invalid, old_state %d, dir %d, type %d",
dir, sch->type, old_state); old_state, dir, sch->type);
goto out_unlock; goto out_unlock;
} }
...@@ -536,7 +521,6 @@ int nf_conntrack_sctp_packet(struct nf_conn *ct, ...@@ -536,7 +521,6 @@ int nf_conntrack_sctp_packet(struct nf_conn *ct,
if (old_state == SCTP_CONNTRACK_COOKIE_ECHOED && if (old_state == SCTP_CONNTRACK_COOKIE_ECHOED &&
dir == IP_CT_DIR_REPLY && dir == IP_CT_DIR_REPLY &&
new_state == SCTP_CONNTRACK_ESTABLISHED) { new_state == SCTP_CONNTRACK_ESTABLISHED) {
pr_debug("Setting assured bit\n");
set_bit(IPS_ASSURED_BIT, &ct->status); set_bit(IPS_ASSURED_BIT, &ct->status);
nf_conntrack_event_cache(IPCT_ASSURED, ct); nf_conntrack_event_cache(IPCT_ASSURED, ct);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment