cregit-Linux how code gets into the kernel

Release 4.7 net/netfilter/ipset/ip_set_getport.c

/* Copyright (C) 2003-2011 Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 */

/* Get Layer-4 data from the packets */

#include <linux/ip.h>
#include <linux/skbuff.h>
#include <linux/icmp.h>
#include <linux/icmpv6.h>
#include <linux/sctp.h>
#include <linux/netfilter_ipv6/ip6_tables.h>
#include <net/ip.h>
#include <net/ipv6.h>

#include <linux/netfilter/ipset/ip_set_getport.h>
#include <linux/export.h>

/* We must handle non-linear skbs */

static bool get_port(const struct sk_buff *skb, int protocol, unsigned int protooff, bool src, __be16 *port, u8 *proto) { switch (protocol) { case IPPROTO_TCP: { struct tcphdr _tcph; const struct tcphdr *th; th = skb_header_pointer(skb, protooff, sizeof(_tcph), &_tcph); if (!th) /* No choice either */ return false; *port = src ? th->source : th->dest; break; } case IPPROTO_SCTP: { sctp_sctphdr_t _sh; const sctp_sctphdr_t *sh; sh = skb_header_pointer(skb, protooff, sizeof(_sh), &_sh); if (!sh) /* No choice either */ return false; *port = src ? sh->source : sh->dest; break; } case IPPROTO_UDP: case IPPROTO_UDPLITE: { struct udphdr _udph; const struct udphdr *uh; uh = skb_header_pointer(skb, protooff, sizeof(_udph), &_udph); if (!uh) /* No choice either */ return false; *port = src ? uh->source : uh->dest; break; } case IPPROTO_ICMP: { struct icmphdr _ich; const struct icmphdr *ic; ic = skb_header_pointer(skb, protooff, sizeof(_ich), &_ich); if (!ic) return false; *port = (__force __be16)htons((ic->type << 8) | ic->code); break; } case IPPROTO_ICMPV6: { struct icmp6hdr _ich; const struct icmp6hdr *ic; ic = skb_header_pointer(skb, protooff, sizeof(_ich), &_ich); if (!ic) return false; *port = (__force __be16) htons((ic->icmp6_type << 8) | ic->icmp6_code); break; } default: break; } *proto = protocol; return true; }

Contributors

PersonTokensPropCommitsCommitProp
jozsef kadlecsikjozsef kadlecsik338100.00%3100.00%
Total338100.00%3100.00%


bool ip_set_get_ip4_port(const struct sk_buff *skb, bool src, __be16 *port, u8 *proto) { const struct iphdr *iph = ip_hdr(skb); unsigned int protooff = skb_network_offset(skb) + ip_hdrlen(skb); int protocol = iph->protocol; /* See comments at tcp_match in ip_tables.c */ if (protocol <= 0) return false; if (ntohs(iph->frag_off) & IP_OFFSET) switch (protocol) { case IPPROTO_TCP: case IPPROTO_SCTP: case IPPROTO_UDP: case IPPROTO_UDPLITE: case IPPROTO_ICMP: /* Port info not available for fragment offset > 0 */ return false; default: /* Other protocols doesn't have ports, * so we can match fragments. */ *proto = protocol; return true; } return get_port(skb, protocol, protooff, src, port, proto); }

Contributors

PersonTokensPropCommitsCommitProp
jozsef kadlecsikjozsef kadlecsik8466.67%250.00%
anders k. pedersenanders k. pedersen3729.37%125.00%
alexander drozdovalexander drozdov53.97%125.00%
Total126100.00%4100.00%

EXPORT_SYMBOL_GPL(ip_set_get_ip4_port); #if IS_ENABLED(CONFIG_IP6_NF_IPTABLES)
bool ip_set_get_ip6_port(const struct sk_buff *skb, bool src, __be16 *port, u8 *proto) { int protoff; u8 nexthdr; __be16 frag_off = 0; nexthdr = ipv6_hdr(skb)->nexthdr; protoff = ipv6_skip_exthdr(skb, skb_network_offset(skb) + sizeof(struct ipv6hdr), &nexthdr, &frag_off); if (protoff < 0 || (frag_off & htons(~0x7)) != 0) return false; return get_port(skb, nexthdr, protoff, src, port, proto); }

Contributors

PersonTokensPropCommitsCommitProp
jozsef kadlecsikjozsef kadlecsik6866.02%240.00%
patrick mchardypatrick mchardy2423.30%120.00%
jesse grossjesse gross65.83%120.00%
alexander drozdovalexander drozdov54.85%120.00%
Total103100.00%5100.00%

EXPORT_SYMBOL_GPL(ip_set_get_ip6_port); #endif
bool ip_set_get_ip_port(const struct sk_buff *skb, u8 pf, bool src, __be16 *port) { bool ret; u8 proto; switch (pf) { case NFPROTO_IPV4: ret = ip_set_get_ip4_port(skb, src, port, &proto); break; case NFPROTO_IPV6: ret = ip_set_get_ip6_port(skb, src, port, &proto); break; default: return false; } if (!ret) return ret; switch (proto) { case IPPROTO_TCP: case IPPROTO_UDP: return true; default: return false; } }

Contributors

PersonTokensPropCommitsCommitProp
jozsef kadlecsikjozsef kadlecsik9696.00%133.33%
patrick mchardypatrick mchardy22.00%133.33%
jan engelhardtjan engelhardt22.00%133.33%
Total100100.00%3100.00%

EXPORT_SYMBOL_GPL(ip_set_get_ip_port);

Overall Contributors

PersonTokensPropCommitsCommitProp
jozsef kadlecsikjozsef kadlecsik62886.86%433.33%
anders k. pedersenanders k. pedersen375.12%18.33%
patrick mchardypatrick mchardy364.98%216.67%
alexander drozdovalexander drozdov101.38%18.33%
jesse grossjesse gross60.83%18.33%
paul gortmakerpaul gortmaker30.41%18.33%
jan engelhardtjan engelhardt20.28%18.33%
igor maravicigor maravic10.14%18.33%
Total723100.00%12100.00%
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.
{% endraw %}