···6666 u_int32_t last_ack; /* Last sequence number seen in opposite dir */6767 u_int32_t last_end; /* Last seq + len */6868 u_int16_t last_win; /* Last window advertisement seen in dir */6969+ /* For SYN packets while we may be out-of-sync */7070+ u_int8_t last_wscale; /* Last window scaling factor seen */7171+ u_int8_t last_flags; /* Last flags set */6972};70737174#endif /* __KERNEL__ */
···9696 if (info->invert & IPT_ECN_OP_MATCH_MASK)9797 return false;98989999- if (info->operation & (IPT_ECN_OP_MATCH_ECE|IPT_ECN_OP_MATCH_CWR)100100- && ip->proto != IPPROTO_TCP) {9999+ if (info->operation & (IPT_ECN_OP_MATCH_ECE|IPT_ECN_OP_MATCH_CWR) &&100100+ ip->proto != IPPROTO_TCP) {101101 printk(KERN_WARNING "ipt_ecn: can't match TCP bits in rule for"102102 " non-tcp packets\n");103103 return false;
+2-2
net/ipv4/netfilter/iptable_mangle.c
···130130 u_int32_t mark;131131132132 /* root is playing with raw sockets. */133133- if (skb->len < sizeof(struct iphdr)134134- || ip_hdrlen(skb) < sizeof(struct iphdr))133133+ if (skb->len < sizeof(struct iphdr) ||134134+ ip_hdrlen(skb) < sizeof(struct iphdr))135135 return NF_ACCEPT;136136137137 /* Save things which could affect route */
+2-2
net/ipv4/netfilter/iptable_security.c
···9494 int (*okfn)(struct sk_buff *))9595{9696 /* Somebody is playing with raw sockets. */9797- if (skb->len < sizeof(struct iphdr)9898- || ip_hdrlen(skb) < sizeof(struct iphdr))9797+ if (skb->len < sizeof(struct iphdr) ||9898+ ip_hdrlen(skb) < sizeof(struct iphdr))9999 return NF_ACCEPT;100100 return ipt_do_table(skb, hook, in, out,101101 dev_net(out)->ipv4.iptable_security);
+14-14
net/ipv4/netfilter/nf_conntrack_proto_icmp.c
···5454static bool icmp_invert_tuple(struct nf_conntrack_tuple *tuple,5555 const struct nf_conntrack_tuple *orig)5656{5757- if (orig->dst.u.icmp.type >= sizeof(invmap)5858- || !invmap[orig->dst.u.icmp.type])5757+ if (orig->dst.u.icmp.type >= sizeof(invmap) ||5858+ !invmap[orig->dst.u.icmp.type])5959 return false;60606161 tuple->src.u.icmp.id = orig->src.u.icmp.id;···101101 [ICMP_ADDRESS] = 1102102 };103103104104- if (ct->tuplehash[0].tuple.dst.u.icmp.type >= sizeof(valid_new)105105- || !valid_new[ct->tuplehash[0].tuple.dst.u.icmp.type]) {104104+ if (ct->tuplehash[0].tuple.dst.u.icmp.type >= sizeof(valid_new) ||105105+ !valid_new[ct->tuplehash[0].tuple.dst.u.icmp.type]) {106106 /* Can't create a new ICMP `conn' with this. */107107 pr_debug("icmp: can't create new conn with type %u\n",108108 ct->tuplehash[0].tuple.dst.u.icmp.type);···201201 }202202203203 /* Need to track icmp error message? */204204- if (icmph->type != ICMP_DEST_UNREACH205205- && icmph->type != ICMP_SOURCE_QUENCH206206- && icmph->type != ICMP_TIME_EXCEEDED207207- && icmph->type != ICMP_PARAMETERPROB208208- && icmph->type != ICMP_REDIRECT)204204+ if (icmph->type != ICMP_DEST_UNREACH &&205205+ icmph->type != ICMP_SOURCE_QUENCH &&206206+ icmph->type != ICMP_TIME_EXCEEDED &&207207+ icmph->type != ICMP_PARAMETERPROB &&208208+ icmph->type != ICMP_REDIRECT)209209 return NF_ACCEPT;210210211211 return icmp_error_message(net, skb, ctinfo, hooknum);···238238static int icmp_nlattr_to_tuple(struct nlattr *tb[],239239 struct nf_conntrack_tuple *tuple)240240{241241- if (!tb[CTA_PROTO_ICMP_TYPE]242242- || !tb[CTA_PROTO_ICMP_CODE]243243- || !tb[CTA_PROTO_ICMP_ID])241241+ if (!tb[CTA_PROTO_ICMP_TYPE] ||242242+ !tb[CTA_PROTO_ICMP_CODE] ||243243+ !tb[CTA_PROTO_ICMP_ID])244244 return -EINVAL;245245246246 tuple->dst.u.icmp.type = nla_get_u8(tb[CTA_PROTO_ICMP_TYPE]);247247 tuple->dst.u.icmp.code = nla_get_u8(tb[CTA_PROTO_ICMP_CODE]);248248 tuple->src.u.icmp.id = nla_get_be16(tb[CTA_PROTO_ICMP_ID]);249249250250- if (tuple->dst.u.icmp.type >= sizeof(invmap)251251- || !invmap[tuple->dst.u.icmp.type])250250+ if (tuple->dst.u.icmp.type >= sizeof(invmap) ||251251+ !invmap[tuple->dst.u.icmp.type])252252 return -EINVAL;253253254254 return 0;
···512512 cnt++;513513 }514514515515- if (ct && unlikely(nf_ct_is_dying(ct) ||516516- !atomic_inc_not_zero(&ct->ct_general.use)))517517- ct = NULL;518518- if (ct || cnt >= NF_CT_EVICTION_RANGE)515515+ if (ct != NULL) {516516+ if (likely(!nf_ct_is_dying(ct) &&517517+ atomic_inc_not_zero(&ct->ct_general.use)))518518+ break;519519+ else520520+ ct = NULL;521521+ }522522+523523+ if (cnt >= NF_CT_EVICTION_RANGE)519524 break;525525+520526 hash = (hash + 1) % nf_conntrack_htable_size;521527 }522528 rcu_read_unlock();
+40-9
net/netfilter/nf_conntrack_proto_tcp.c
···896896 /* b) This SYN/ACK acknowledges a SYN that we earlier897897 * ignored as invalid. This means that the client and898898 * the server are both in sync, while the firewall is899899- * not. We kill this session and block the SYN/ACK so900900- * that the client cannot but retransmit its SYN and901901- * thus initiate a clean new session.899899+ * not. We get in sync from the previously annotated900900+ * values.902901 */903903- spin_unlock_bh(&ct->lock);904904- if (LOG_INVALID(net, IPPROTO_TCP))905905- nf_log_packet(pf, 0, skb, NULL, NULL, NULL,906906- "nf_ct_tcp: killing out of sync session ");907907- nf_ct_kill(ct);908908- return NF_DROP;902902+ old_state = TCP_CONNTRACK_SYN_SENT;903903+ new_state = TCP_CONNTRACK_SYN_RECV;904904+ ct->proto.tcp.seen[ct->proto.tcp.last_dir].td_end =905905+ ct->proto.tcp.last_end;906906+ ct->proto.tcp.seen[ct->proto.tcp.last_dir].td_maxend =907907+ ct->proto.tcp.last_end;908908+ ct->proto.tcp.seen[ct->proto.tcp.last_dir].td_maxwin =909909+ ct->proto.tcp.last_win == 0 ?910910+ 1 : ct->proto.tcp.last_win;911911+ ct->proto.tcp.seen[ct->proto.tcp.last_dir].td_scale =912912+ ct->proto.tcp.last_wscale;913913+ ct->proto.tcp.seen[ct->proto.tcp.last_dir].flags =914914+ ct->proto.tcp.last_flags;915915+ memset(&ct->proto.tcp.seen[dir], 0,916916+ sizeof(struct ip_ct_tcp_state));917917+ break;909918 }910919 ct->proto.tcp.last_index = index;911920 ct->proto.tcp.last_dir = dir;912921 ct->proto.tcp.last_seq = ntohl(th->seq);913922 ct->proto.tcp.last_end =914923 segment_seq_plus_len(ntohl(th->seq), skb->len, dataoff, th);924924+ ct->proto.tcp.last_win = ntohs(th->window);915925926926+ /* a) This is a SYN in ORIGINAL. The client and the server927927+ * may be in sync but we are not. In that case, we annotate928928+ * the TCP options and let the packet go through. If it is a929929+ * valid SYN packet, the server will reply with a SYN/ACK, and930930+ * then we'll get in sync. Otherwise, the server ignores it. */931931+ if (index == TCP_SYN_SET && dir == IP_CT_DIR_ORIGINAL) {932932+ struct ip_ct_tcp_state seen = {};933933+934934+ ct->proto.tcp.last_flags =935935+ ct->proto.tcp.last_wscale = 0;936936+ tcp_options(skb, dataoff, th, &seen);937937+ if (seen.flags & IP_CT_TCP_FLAG_WINDOW_SCALE) {938938+ ct->proto.tcp.last_flags |=939939+ IP_CT_TCP_FLAG_WINDOW_SCALE;940940+ ct->proto.tcp.last_wscale = seen.td_scale;941941+ }942942+ if (seen.flags & IP_CT_TCP_FLAG_SACK_PERM) {943943+ ct->proto.tcp.last_flags |=944944+ IP_CT_TCP_FLAG_SACK_PERM;945945+ }946946+ }916947 spin_unlock_bh(&ct->lock);917948 if (LOG_INVALID(net, IPPROTO_TCP))918949 nf_log_packet(pf, 0, skb, NULL, NULL, NULL,
+1-2
net/netfilter/nfnetlink_log.c
···666666{667667 struct netlink_notify *n = ptr;668668669669- if (event == NETLINK_URELEASE &&670670- n->protocol == NETLINK_NETFILTER && n->pid) {669669+ if (event == NETLINK_URELEASE && n->protocol == NETLINK_NETFILTER) {671670 int i;672671673672 /* destroy all instances for this pid */
+1-2
net/netfilter/nfnetlink_queue.c
···574574{575575 struct netlink_notify *n = ptr;576576577577- if (event == NETLINK_URELEASE &&578578- n->protocol == NETLINK_NETFILTER && n->pid) {577577+ if (event == NETLINK_URELEASE && n->protocol == NETLINK_NETFILTER) {579578 int i;580579581580 /* destroy all instances for this pid */