[NETFILTER]: nf_conntrack_sctp: consolidate sctp_packet() error paths
Consolidate error paths and use proper symbolic return value instead of magic values. Signed-off-by: Patrick McHardy <kaber@trash.net> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
Родитель
8528819adc
Коммит
b37e933ac7
|
@ -291,7 +291,7 @@ static int new_state(enum ip_conntrack_dir dir,
|
||||||
return sctp_conntracks[dir][i][cur_state];
|
return sctp_conntracks[dir][i][cur_state];
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Returns verdict for packet, or -1 for invalid. */
|
/* Returns verdict for packet, or -NF_ACCEPT for invalid. */
|
||||||
static int sctp_packet(struct nf_conn *ct,
|
static int sctp_packet(struct nf_conn *ct,
|
||||||
const struct sk_buff *skb,
|
const struct sk_buff *skb,
|
||||||
unsigned int dataoff,
|
unsigned int dataoff,
|
||||||
|
@ -308,10 +308,10 @@ static int sctp_packet(struct nf_conn *ct,
|
||||||
|
|
||||||
sh = skb_header_pointer(skb, dataoff, sizeof(_sctph), &_sctph);
|
sh = skb_header_pointer(skb, dataoff, sizeof(_sctph), &_sctph);
|
||||||
if (sh == NULL)
|
if (sh == NULL)
|
||||||
return -1;
|
goto out;
|
||||||
|
|
||||||
if (do_basic_checks(ct, skb, dataoff, map) != 0)
|
if (do_basic_checks(ct, skb, dataoff, map) != 0)
|
||||||
return -1;
|
goto out;
|
||||||
|
|
||||||
/* Check the verification tag (Sec 8.5) */
|
/* Check the verification tag (Sec 8.5) */
|
||||||
if (!test_bit(SCTP_CID_INIT, map) &&
|
if (!test_bit(SCTP_CID_INIT, map) &&
|
||||||
|
@ -321,7 +321,7 @@ static int sctp_packet(struct nf_conn *ct,
|
||||||
!test_bit(SCTP_CID_SHUTDOWN_ACK, map) &&
|
!test_bit(SCTP_CID_SHUTDOWN_ACK, map) &&
|
||||||
sh->vtag != ct->proto.sctp.vtag[dir]) {
|
sh->vtag != ct->proto.sctp.vtag[dir]) {
|
||||||
pr_debug("Verification tag check failed\n");
|
pr_debug("Verification tag check failed\n");
|
||||||
return -1;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
oldsctpstate = newconntrack = SCTP_CONNTRACK_MAX;
|
oldsctpstate = newconntrack = SCTP_CONNTRACK_MAX;
|
||||||
|
@ -331,31 +331,23 @@ static int sctp_packet(struct nf_conn *ct,
|
||||||
/* Special cases of Verification tag check (Sec 8.5.1) */
|
/* Special cases of Verification tag check (Sec 8.5.1) */
|
||||||
if (sch->type == SCTP_CID_INIT) {
|
if (sch->type == SCTP_CID_INIT) {
|
||||||
/* Sec 8.5.1 (A) */
|
/* Sec 8.5.1 (A) */
|
||||||
if (sh->vtag != 0) {
|
if (sh->vtag != 0)
|
||||||
write_unlock_bh(&sctp_lock);
|
goto out_unlock;
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
} else if (sch->type == SCTP_CID_ABORT) {
|
} else if (sch->type == SCTP_CID_ABORT) {
|
||||||
/* Sec 8.5.1 (B) */
|
/* Sec 8.5.1 (B) */
|
||||||
if (sh->vtag != ct->proto.sctp.vtag[dir] &&
|
if (sh->vtag != ct->proto.sctp.vtag[dir] &&
|
||||||
sh->vtag != ct->proto.sctp.vtag[!dir]) {
|
sh->vtag != ct->proto.sctp.vtag[!dir])
|
||||||
write_unlock_bh(&sctp_lock);
|
goto out_unlock;
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
} else if (sch->type == SCTP_CID_SHUTDOWN_COMPLETE) {
|
} else if (sch->type == SCTP_CID_SHUTDOWN_COMPLETE) {
|
||||||
/* Sec 8.5.1 (C) */
|
/* Sec 8.5.1 (C) */
|
||||||
if (sh->vtag != ct->proto.sctp.vtag[dir] &&
|
if (sh->vtag != ct->proto.sctp.vtag[dir] &&
|
||||||
sh->vtag != ct->proto.sctp.vtag[!dir] &&
|
sh->vtag != ct->proto.sctp.vtag[!dir] &&
|
||||||
(sch->flags & 1)) {
|
(sch->flags & 1))
|
||||||
write_unlock_bh(&sctp_lock);
|
goto out_unlock;
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
} else if (sch->type == SCTP_CID_COOKIE_ECHO) {
|
} else if (sch->type == SCTP_CID_COOKIE_ECHO) {
|
||||||
/* Sec 8.5.1 (D) */
|
/* Sec 8.5.1 (D) */
|
||||||
if (sh->vtag != ct->proto.sctp.vtag[dir]) {
|
if (sh->vtag != ct->proto.sctp.vtag[dir])
|
||||||
write_unlock_bh(&sctp_lock);
|
goto out_unlock;
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
oldsctpstate = ct->proto.sctp.state;
|
oldsctpstate = ct->proto.sctp.state;
|
||||||
|
@ -366,8 +358,7 @@ static int sctp_packet(struct nf_conn *ct,
|
||||||
pr_debug("nf_conntrack_sctp: Invalid dir=%i ctype=%u "
|
pr_debug("nf_conntrack_sctp: Invalid dir=%i ctype=%u "
|
||||||
"conntrack=%u\n",
|
"conntrack=%u\n",
|
||||||
dir, sch->type, oldsctpstate);
|
dir, sch->type, oldsctpstate);
|
||||||
write_unlock_bh(&sctp_lock);
|
goto out_unlock;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If it is an INIT or an INIT ACK note down the vtag */
|
/* If it is an INIT or an INIT ACK note down the vtag */
|
||||||
|
@ -377,10 +368,8 @@ static int sctp_packet(struct nf_conn *ct,
|
||||||
|
|
||||||
ih = skb_header_pointer(skb, offset + sizeof(sctp_chunkhdr_t),
|
ih = skb_header_pointer(skb, offset + sizeof(sctp_chunkhdr_t),
|
||||||
sizeof(_inithdr), &_inithdr);
|
sizeof(_inithdr), &_inithdr);
|
||||||
if (ih == NULL) {
|
if (ih == NULL)
|
||||||
write_unlock_bh(&sctp_lock);
|
goto out_unlock;
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
pr_debug("Setting vtag %x for dir %d\n",
|
pr_debug("Setting vtag %x for dir %d\n",
|
||||||
ih->init_tag, !dir);
|
ih->init_tag, !dir);
|
||||||
ct->proto.sctp.vtag[!dir] = ih->init_tag;
|
ct->proto.sctp.vtag[!dir] = ih->init_tag;
|
||||||
|
@ -403,6 +392,11 @@ static int sctp_packet(struct nf_conn *ct,
|
||||||
}
|
}
|
||||||
|
|
||||||
return NF_ACCEPT;
|
return NF_ACCEPT;
|
||||||
|
|
||||||
|
out_unlock:
|
||||||
|
write_unlock_bh(&sctp_lock);
|
||||||
|
out:
|
||||||
|
return -NF_ACCEPT;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Called when a new connection for this protocol found. */
|
/* Called when a new connection for this protocol found. */
|
||||||
|
|
Загрузка…
Ссылка в новой задаче