Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 09f263cd authored by Jan Engelhardt's avatar Jan Engelhardt Committed by Patrick McHardy
Browse files

[NETFILTER]: nf_conntrack: use bool type in struct nf_conntrack_l4proto

parent 8ce8439a
Loading
Loading
Loading
Loading
+6 −7
Original line number Diff line number Diff line
@@ -25,14 +25,13 @@ struct nf_conntrack_l4proto

	/* Try to fill in the third arg: dataoff is offset past network protocol
           hdr.  Return true if possible. */
	int (*pkt_to_tuple)(const struct sk_buff *skb,
			    unsigned int dataoff,
	bool (*pkt_to_tuple)(const struct sk_buff *skb, unsigned int dataoff,
			     struct nf_conntrack_tuple *tuple);

	/* Invert the per-proto part of the tuple: ie. turn xmit into reply.
	 * Some packets can't be inverted: return 0 in that case.
	 */
	int (*invert_tuple)(struct nf_conntrack_tuple *inverse,
	bool (*invert_tuple)(struct nf_conntrack_tuple *inverse,
			     const struct nf_conntrack_tuple *orig);

	/* Returns verdict for packet, or -1 for invalid. */
@@ -45,7 +44,7 @@ struct nf_conntrack_l4proto

	/* Called when a new connection for this protocol found;
	 * returns TRUE if it's OK.  If so, packet() called next. */
	int (*new)(struct nf_conn *ct, const struct sk_buff *skb,
	bool (*new)(struct nf_conn *ct, const struct sk_buff *skb,
		    unsigned int dataoff);

	/* Called when a conntrack entry is destroyed */
+12 −13
Original line number Diff line number Diff line
@@ -22,8 +22,7 @@

static unsigned long nf_ct_icmp_timeout __read_mostly = 30*HZ;

static int icmp_pkt_to_tuple(const struct sk_buff *skb,
			     unsigned int dataoff,
static bool icmp_pkt_to_tuple(const struct sk_buff *skb, unsigned int dataoff,
			      struct nf_conntrack_tuple *tuple)
{
	const struct icmphdr *hp;
@@ -31,13 +30,13 @@ static int icmp_pkt_to_tuple(const struct sk_buff *skb,

	hp = skb_header_pointer(skb, dataoff, sizeof(_hdr), &_hdr);
	if (hp == NULL)
		return 0;
		return false;

	tuple->dst.u.icmp.type = hp->type;
	tuple->src.u.icmp.id = hp->un.echo.id;
	tuple->dst.u.icmp.code = hp->code;

	return 1;
	return true;
}

/* Add 1; spaces filled with 0. */
@@ -52,17 +51,17 @@ static const u_int8_t invmap[] = {
	[ICMP_ADDRESSREPLY] = ICMP_ADDRESS + 1
};

static int icmp_invert_tuple(struct nf_conntrack_tuple *tuple,
static bool icmp_invert_tuple(struct nf_conntrack_tuple *tuple,
			      const struct nf_conntrack_tuple *orig)
{
	if (orig->dst.u.icmp.type >= sizeof(invmap)
	    || !invmap[orig->dst.u.icmp.type])
		return 0;
		return false;

	tuple->src.u.icmp.id = orig->src.u.icmp.id;
	tuple->dst.u.icmp.type = invmap[orig->dst.u.icmp.type] - 1;
	tuple->dst.u.icmp.code = orig->dst.u.icmp.code;
	return 1;
	return true;
}

/* Print out the per-protocol part of the tuple. */
@@ -101,8 +100,8 @@ static int icmp_packet(struct nf_conn *ct,
}

/* Called when a new connection for this protocol found. */
static int icmp_new(struct nf_conn *ct,
		    const struct sk_buff *skb, unsigned int dataoff)
static bool icmp_new(struct nf_conn *ct, const struct sk_buff *skb,
		     unsigned int dataoff)
{
	static const u_int8_t valid_new[] = {
		[ICMP_ECHO] = 1,
@@ -117,10 +116,10 @@ static int icmp_new(struct nf_conn *ct,
		pr_debug("icmp: can't create new conn with type %u\n",
			 ct->tuplehash[0].tuple.dst.u.icmp.type);
		NF_CT_DUMP_TUPLE(&ct->tuplehash[0].tuple);
		return 0;
		return false;
	}
	atomic_set(&ct->proto.icmp.count, 0);
	return 1;
	return true;
}

/* Returns conntrack if it dealt with ICMP, and filled in skb fields */
+13 −14
Original line number Diff line number Diff line
@@ -28,7 +28,7 @@

static unsigned long nf_ct_icmpv6_timeout __read_mostly = 30*HZ;

static int icmpv6_pkt_to_tuple(const struct sk_buff *skb,
static bool icmpv6_pkt_to_tuple(const struct sk_buff *skb,
				unsigned int dataoff,
				struct nf_conntrack_tuple *tuple)
{
@@ -37,12 +37,12 @@ static int icmpv6_pkt_to_tuple(const struct sk_buff *skb,

	hp = skb_header_pointer(skb, dataoff, sizeof(_hdr), &_hdr);
	if (hp == NULL)
		return 0;
		return false;
	tuple->dst.u.icmp.type = hp->icmp6_type;
	tuple->src.u.icmp.id = hp->icmp6_identifier;
	tuple->dst.u.icmp.code = hp->icmp6_code;

	return 1;
	return true;
}

/* Add 1; spaces filled with 0. */
@@ -53,17 +53,17 @@ static const u_int8_t invmap[] = {
	[ICMPV6_NI_REPLY - 128]		= ICMPV6_NI_REPLY +1
};

static int icmpv6_invert_tuple(struct nf_conntrack_tuple *tuple,
static bool icmpv6_invert_tuple(struct nf_conntrack_tuple *tuple,
				const struct nf_conntrack_tuple *orig)
{
	int type = orig->dst.u.icmp.type - 128;
	if (type < 0 || type >= sizeof(invmap) || !invmap[type])
		return 0;
		return false;

	tuple->src.u.icmp.id   = orig->src.u.icmp.id;
	tuple->dst.u.icmp.type = invmap[type] - 1;
	tuple->dst.u.icmp.code = orig->dst.u.icmp.code;
	return 1;
	return true;
}

/* Print out the per-protocol part of the tuple. */
@@ -102,8 +102,7 @@ static int icmpv6_packet(struct nf_conn *ct,
}

/* Called when a new connection for this protocol found. */
static int icmpv6_new(struct nf_conn *ct,
		      const struct sk_buff *skb,
static bool icmpv6_new(struct nf_conn *ct, const struct sk_buff *skb,
		       unsigned int dataoff)
{
	static const u_int8_t valid_new[] = {
@@ -117,10 +116,10 @@ static int icmpv6_new(struct nf_conn *ct,
		pr_debug("icmpv6: can't create new conn with type %u\n",
			 type + 128);
		NF_CT_DUMP_TUPLE(&ct->tuplehash[0].tuple);
		return 0;
		return false;
	}
	atomic_set(&ct->proto.icmp.count, 0);
	return 1;
	return true;
}

static int
+11 −11
Original line number Diff line number Diff line
@@ -393,29 +393,29 @@ dccp_state_table[CT_DCCP_ROLE_MAX + 1][DCCP_PKT_SYNCACK + 1][CT_DCCP_MAX + 1] =
	},
};

static int dccp_pkt_to_tuple(const struct sk_buff *skb, unsigned int dataoff,
static bool dccp_pkt_to_tuple(const struct sk_buff *skb, unsigned int dataoff,
			      struct nf_conntrack_tuple *tuple)
{
	struct dccp_hdr _hdr, *dh;

	dh = skb_header_pointer(skb, dataoff, sizeof(_hdr), &_hdr);
	if (dh == NULL)
		return 0;
		return false;

	tuple->src.u.dccp.port = dh->dccph_sport;
	tuple->dst.u.dccp.port = dh->dccph_dport;
	return 1;
	return true;
}

static int dccp_invert_tuple(struct nf_conntrack_tuple *inv,
static bool dccp_invert_tuple(struct nf_conntrack_tuple *inv,
			      const struct nf_conntrack_tuple *tuple)
{
	inv->src.u.dccp.port = tuple->dst.u.dccp.port;
	inv->dst.u.dccp.port = tuple->src.u.dccp.port;
	return 1;
	return true;
}

static int dccp_new(struct nf_conn *ct, const struct sk_buff *skb,
static bool dccp_new(struct nf_conn *ct, const struct sk_buff *skb,
		     unsigned int dataoff)
{
	struct dccp_hdr _dh, *dh;
@@ -442,12 +442,12 @@ static int dccp_new(struct nf_conn *ct, const struct sk_buff *skb,
	ct->proto.dccp.role[IP_CT_DIR_ORIGINAL] = CT_DCCP_ROLE_CLIENT;
	ct->proto.dccp.role[IP_CT_DIR_REPLY] = CT_DCCP_ROLE_SERVER;
	ct->proto.dccp.state = CT_DCCP_NONE;
	return 1;
	return true;

out_invalid:
	if (LOG_INVALID(IPPROTO_DCCP))
		nf_log_packet(nf_ct_l3num(ct), 0, skb, NULL, NULL, NULL, msg);
	return 0;
	return false;
}

static u64 dccp_ack_seq(const struct dccp_hdr *dh)
+10 −10
Original line number Diff line number Diff line
@@ -14,23 +14,23 @@

static unsigned int nf_ct_generic_timeout __read_mostly = 600*HZ;

static int generic_pkt_to_tuple(const struct sk_buff *skb,
static bool generic_pkt_to_tuple(const struct sk_buff *skb,
				 unsigned int dataoff,
				 struct nf_conntrack_tuple *tuple)
{
	tuple->src.u.all = 0;
	tuple->dst.u.all = 0;

	return 1;
	return true;
}

static int generic_invert_tuple(struct nf_conntrack_tuple *tuple,
static bool generic_invert_tuple(struct nf_conntrack_tuple *tuple,
				 const struct nf_conntrack_tuple *orig)
{
	tuple->src.u.all = 0;
	tuple->dst.u.all = 0;

	return 1;
	return true;
}

/* Print out the per-protocol part of the tuple. */
@@ -53,10 +53,10 @@ static int packet(struct nf_conn *ct,
}

/* Called when a new connection for this protocol found. */
static int new(struct nf_conn *ct, const struct sk_buff *skb,
static bool new(struct nf_conn *ct, const struct sk_buff *skb,
		unsigned int dataoff)
{
	return 1;
	return true;
}

#ifdef CONFIG_SYSCTL
Loading