Skip to content

Commit

Permalink
[NETFILTER]: add some consts, remove some casts
Browse files Browse the repository at this point in the history
Make a number of variables const and/or remove unneeded casts.

Signed-off-by: Jan Engelhardt <[email protected]>
Signed-off-by: Patrick McHardy <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
Jan Engelhardt authored and David S. Miller committed Jul 11, 2007
1 parent e1931b7 commit a47362a
Show file tree
Hide file tree
Showing 36 changed files with 136 additions and 100 deletions.
11 changes: 6 additions & 5 deletions net/ipv4/netfilter/ipt_CLUSTERIP.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,12 +235,13 @@ clusterip_del_node(struct clusterip_config *c, u_int16_t nodenum)
#endif

static inline u_int32_t
clusterip_hashfn(struct sk_buff *skb, struct clusterip_config *config)
clusterip_hashfn(const struct sk_buff *skb,
const struct clusterip_config *config)
{
struct iphdr *iph = ip_hdr(skb);
const struct iphdr *iph = ip_hdr(skb);
unsigned long hashval;
u_int16_t sport, dport;
u_int16_t *ports;
const u_int16_t *ports;

switch (iph->protocol) {
case IPPROTO_TCP:
Expand All @@ -249,7 +250,7 @@ clusterip_hashfn(struct sk_buff *skb, struct clusterip_config *config)
case IPPROTO_SCTP:
case IPPROTO_DCCP:
case IPPROTO_ICMP:
ports = (void *)iph+iph->ihl*4;
ports = (const void *)iph+iph->ihl*4;
sport = ports[0];
dport = ports[1];
break;
Expand Down Expand Up @@ -289,7 +290,7 @@ clusterip_hashfn(struct sk_buff *skb, struct clusterip_config *config)
}

static inline int
clusterip_responsible(struct clusterip_config *config, u_int32_t hash)
clusterip_responsible(const struct clusterip_config *config, u_int32_t hash)
{
return test_bit(hash - 1, &config->local_nodes);
}
Expand Down
26 changes: 17 additions & 9 deletions net/ipv4/netfilter/ipt_LOG.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ static void dump_packet(const struct nf_loginfo *info,
const struct sk_buff *skb,
unsigned int iphoff)
{
struct iphdr _iph, *ih;
struct iphdr _iph;
const struct iphdr *ih;
unsigned int logflags;

if (info->type == NF_LOG_TYPE_LOG)
Expand Down Expand Up @@ -100,7 +101,8 @@ static void dump_packet(const struct nf_loginfo *info,

switch (ih->protocol) {
case IPPROTO_TCP: {
struct tcphdr _tcph, *th;
struct tcphdr _tcph;
const struct tcphdr *th;

/* Max length: 10 "PROTO=TCP " */
printk("PROTO=TCP ");
Expand Down Expand Up @@ -151,7 +153,7 @@ static void dump_packet(const struct nf_loginfo *info,
if ((logflags & IPT_LOG_TCPOPT)
&& th->doff * 4 > sizeof(struct tcphdr)) {
unsigned char _opt[4 * 15 - sizeof(struct tcphdr)];
unsigned char *op;
const unsigned char *op;
unsigned int i, optsize;

optsize = th->doff * 4 - sizeof(struct tcphdr);
Expand All @@ -173,7 +175,8 @@ static void dump_packet(const struct nf_loginfo *info,
}
case IPPROTO_UDP:
case IPPROTO_UDPLITE: {
struct udphdr _udph, *uh;
struct udphdr _udph;
const struct udphdr *uh;

if (ih->protocol == IPPROTO_UDP)
/* Max length: 10 "PROTO=UDP " */
Expand All @@ -200,7 +203,8 @@ static void dump_packet(const struct nf_loginfo *info,
break;
}
case IPPROTO_ICMP: {
struct icmphdr _icmph, *ich;
struct icmphdr _icmph;
const struct icmphdr *ich;
static const size_t required_len[NR_ICMP_TYPES+1]
= { [ICMP_ECHOREPLY] = 4,
[ICMP_DEST_UNREACH]
Expand Down Expand Up @@ -285,7 +289,8 @@ static void dump_packet(const struct nf_loginfo *info,
}
/* Max Length */
case IPPROTO_AH: {
struct ip_auth_hdr _ahdr, *ah;
struct ip_auth_hdr _ahdr;
const struct ip_auth_hdr *ah;

if (ntohs(ih->frag_off) & IP_OFFSET)
break;
Expand All @@ -307,7 +312,8 @@ static void dump_packet(const struct nf_loginfo *info,
break;
}
case IPPROTO_ESP: {
struct ip_esp_hdr _esph, *eh;
struct ip_esp_hdr _esph;
const struct ip_esp_hdr *eh;

/* Max length: 10 "PROTO=ESP " */
printk("PROTO=ESP ");
Expand Down Expand Up @@ -385,11 +391,13 @@ ipt_log_packet(unsigned int pf,
out ? out->name : "");
#ifdef CONFIG_BRIDGE_NETFILTER
if (skb->nf_bridge) {
struct net_device *physindev = skb->nf_bridge->physindev;
struct net_device *physoutdev = skb->nf_bridge->physoutdev;
const struct net_device *physindev;
const struct net_device *physoutdev;

physindev = skb->nf_bridge->physindev;
if (physindev && in != physindev)
printk("PHYSIN=%s ", physindev->name);
physoutdev = skb->nf_bridge->physoutdev;
if (physoutdev && out != physoutdev)
printk("PHYSOUT=%s ", physoutdev->name);
}
Expand Down
8 changes: 4 additions & 4 deletions net/ipv4/netfilter/ipt_MASQUERADE.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ masquerade_target(struct sk_buff **pskb,
enum ip_conntrack_info ctinfo;
struct nf_nat_range newrange;
const struct nf_nat_multi_range_compat *mr;
struct rtable *rt;
const struct rtable *rt;
__be32 newsrc;

NF_CT_ASSERT(hooknum == NF_IP_POST_ROUTING);
Expand Down Expand Up @@ -112,7 +112,7 @@ masquerade_target(struct sk_buff **pskb,
static inline int
device_cmp(struct nf_conn *i, void *ifindex)
{
struct nf_conn_nat *nat = nfct_nat(i);
const struct nf_conn_nat *nat = nfct_nat(i);
int ret;

if (!nat)
Expand All @@ -129,7 +129,7 @@ static int masq_device_event(struct notifier_block *this,
unsigned long event,
void *ptr)
{
struct net_device *dev = ptr;
const struct net_device *dev = ptr;

if (event == NETDEV_DOWN) {
/* Device was downed. Search entire table for
Expand All @@ -147,7 +147,7 @@ static int masq_inet_event(struct notifier_block *this,
unsigned long event,
void *ptr)
{
struct net_device *dev = ((struct in_ifaddr *)ptr)->ifa_dev->dev;
const struct net_device *dev = ((struct in_ifaddr *)ptr)->ifa_dev->dev;

if (event == NETDEV_DOWN) {
/* IP address was deleted. Search entire table for
Expand Down
2 changes: 1 addition & 1 deletion net/ipv4/netfilter/ipt_REJECT.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ static void send_reset(struct sk_buff *oldskb, int hook)
tcph->check = 0;
tcph->check = tcp_v4_check(sizeof(struct tcphdr),
niph->saddr, niph->daddr,
csum_partial((char *)tcph,
csum_partial(tcph,
sizeof(struct tcphdr), 0));

/* Set DF, id = 0 */
Expand Down
2 changes: 1 addition & 1 deletion net/ipv4/netfilter/ipt_TTL.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ static bool ipt_ttl_checkentry(const char *tablename,
void *targinfo,
unsigned int hook_mask)
{
struct ipt_TTL_info *info = targinfo;
const struct ipt_TTL_info *info = targinfo;

if (info->mode > IPT_TTL_MAXMODE) {
printk(KERN_WARNING "ipt_TTL: invalid or unknown Mode %u\n",
Expand Down
6 changes: 3 additions & 3 deletions net/ipv4/netfilter/ipt_ULOG.c
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ static bool ipt_ulog_checkentry(const char *tablename,
void *targinfo,
unsigned int hookmask)
{
struct ipt_ulog_info *loginfo = (struct ipt_ulog_info *) targinfo;
const struct ipt_ulog_info *loginfo = targinfo;

if (loginfo->prefix[sizeof(loginfo->prefix) - 1] != '\0') {
DEBUGP("ipt_ULOG: prefix term %i\n",
Expand All @@ -359,7 +359,7 @@ struct compat_ipt_ulog_info {

static void compat_from_user(void *dst, void *src)
{
struct compat_ipt_ulog_info *cl = src;
const struct compat_ipt_ulog_info *cl = src;
struct ipt_ulog_info l = {
.nl_group = cl->nl_group,
.copy_range = cl->copy_range,
Expand All @@ -372,7 +372,7 @@ static void compat_from_user(void *dst, void *src)

static int compat_to_user(void __user *dst, void *src)
{
struct ipt_ulog_info *l = src;
const struct ipt_ulog_info *l = src;
struct compat_ipt_ulog_info cl = {
.nl_group = l->nl_group,
.copy_range = l->copy_range,
Expand Down
3 changes: 2 additions & 1 deletion net/ipv4/netfilter/ipt_ah.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ match(const struct sk_buff *skb,
unsigned int protoff,
bool *hotdrop)
{
struct ip_auth_hdr _ahdr, *ah;
struct ip_auth_hdr _ahdr;
const struct ip_auth_hdr *ah;
const struct ipt_ah *ahinfo = matchinfo;

/* Must not be a fragment. */
Expand Down
3 changes: 2 additions & 1 deletion net/ipv4/netfilter/ipt_ecn.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ static inline bool match_tcp(const struct sk_buff *skb,
const struct ipt_ecn_info *einfo,
bool *hotdrop)
{
struct tcphdr _tcph, *th;
struct tcphdr _tcph;
const struct tcphdr *th;

/* In practice, TCP match does this, so can't fail. But let's
* be good citizens.
Expand Down
2 changes: 1 addition & 1 deletion net/ipv4/netfilter/ipt_recent.c
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ struct recent_iter_state {
static void *recent_seq_start(struct seq_file *seq, loff_t *pos)
{
struct recent_iter_state *st = seq->private;
struct recent_table *t = st->table;
const struct recent_table *t = st->table;
struct recent_entry *e;
loff_t p = *pos;

Expand Down
4 changes: 2 additions & 2 deletions net/ipv4/netfilter/nf_nat_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ nf_nat_mangle_tcp_packet(struct sk_buff **pskb,
tcph->check = 0;
tcph->check = tcp_v4_check(datalen,
iph->saddr, iph->daddr,
csum_partial((char *)tcph,
csum_partial(tcph,
datalen, 0));
}
} else
Expand Down Expand Up @@ -278,7 +278,7 @@ nf_nat_mangle_udp_packet(struct sk_buff **pskb,
udph->check = 0;
udph->check = csum_tcpudp_magic(iph->saddr, iph->daddr,
datalen, IPPROTO_UDP,
csum_partial((char *)udph,
csum_partial(udph,
datalen, 0));
if (!udph->check)
udph->check = CSUM_MANGLED_0;
Expand Down
2 changes: 1 addition & 1 deletion net/ipv6/netfilter/ip6t_HL.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ static bool ip6t_hl_checkentry(const char *tablename,
void *targinfo,
unsigned int hook_mask)
{
struct ip6t_HL_info *info = targinfo;
const struct ip6t_HL_info *info = targinfo;

if (info->mode > IP6T_HL_MAXMODE) {
printk(KERN_WARNING "ip6t_HL: invalid or unknown Mode %u\n",
Expand Down
27 changes: 18 additions & 9 deletions net/ipv6/netfilter/ip6t_LOG.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ static void dump_packet(const struct nf_loginfo *info,
{
u_int8_t currenthdr;
int fragment;
struct ipv6hdr _ip6h, *ih;
struct ipv6hdr _ip6h;
const struct ipv6hdr *ih;
unsigned int ptr;
unsigned int hdrlen = 0;
unsigned int logflags;
Expand Down Expand Up @@ -78,7 +79,8 @@ static void dump_packet(const struct nf_loginfo *info,
ptr = ip6hoff + sizeof(struct ipv6hdr);
currenthdr = ih->nexthdr;
while (currenthdr != NEXTHDR_NONE && ip6t_ext_hdr(currenthdr)) {
struct ipv6_opt_hdr _hdr, *hp;
struct ipv6_opt_hdr _hdr;
const struct ipv6_opt_hdr *hp;

hp = skb_header_pointer(skb, ptr, sizeof(_hdr), &_hdr);
if (hp == NULL) {
Expand All @@ -92,7 +94,8 @@ static void dump_packet(const struct nf_loginfo *info,

switch (currenthdr) {
case IPPROTO_FRAGMENT: {
struct frag_hdr _fhdr, *fh;
struct frag_hdr _fhdr;
const struct frag_hdr *fh;

printk("FRAG:");
fh = skb_header_pointer(skb, ptr, sizeof(_fhdr),
Expand Down Expand Up @@ -131,7 +134,8 @@ static void dump_packet(const struct nf_loginfo *info,
/* Max Length */
case IPPROTO_AH:
if (logflags & IP6T_LOG_IPOPT) {
struct ip_auth_hdr _ahdr, *ah;
struct ip_auth_hdr _ahdr;
const struct ip_auth_hdr *ah;

/* Max length: 3 "AH " */
printk("AH ");
Expand Down Expand Up @@ -162,7 +166,8 @@ static void dump_packet(const struct nf_loginfo *info,
break;
case IPPROTO_ESP:
if (logflags & IP6T_LOG_IPOPT) {
struct ip_esp_hdr _esph, *eh;
struct ip_esp_hdr _esph;
const struct ip_esp_hdr *eh;

/* Max length: 4 "ESP " */
printk("ESP ");
Expand Down Expand Up @@ -202,7 +207,8 @@ static void dump_packet(const struct nf_loginfo *info,

switch (currenthdr) {
case IPPROTO_TCP: {
struct tcphdr _tcph, *th;
struct tcphdr _tcph;
const struct tcphdr *th;

/* Max length: 10 "PROTO=TCP " */
printk("PROTO=TCP ");
Expand Down Expand Up @@ -250,7 +256,8 @@ static void dump_packet(const struct nf_loginfo *info,

if ((logflags & IP6T_LOG_TCPOPT)
&& th->doff * 4 > sizeof(struct tcphdr)) {
u_int8_t _opt[60 - sizeof(struct tcphdr)], *op;
u_int8_t _opt[60 - sizeof(struct tcphdr)];
const u_int8_t *op;
unsigned int i;
unsigned int optsize = th->doff * 4
- sizeof(struct tcphdr);
Expand All @@ -273,7 +280,8 @@ static void dump_packet(const struct nf_loginfo *info,
}
case IPPROTO_UDP:
case IPPROTO_UDPLITE: {
struct udphdr _udph, *uh;
struct udphdr _udph;
const struct udphdr *uh;

if (currenthdr == IPPROTO_UDP)
/* Max length: 10 "PROTO=UDP " */
Expand All @@ -298,7 +306,8 @@ static void dump_packet(const struct nf_loginfo *info,
break;
}
case IPPROTO_ICMPV6: {
struct icmp6hdr _icmp6h, *ic;
struct icmp6hdr _icmp6h;
const struct icmp6hdr *ic;

/* Max length: 13 "PROTO=ICMPv6 " */
printk("PROTO=ICMPv6 ");
Expand Down
2 changes: 1 addition & 1 deletion net/ipv6/netfilter/ip6t_REJECT.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ static void send_reset(struct sk_buff *oldskb)
tcph->check = csum_ipv6_magic(&ipv6_hdr(nskb)->saddr,
&ipv6_hdr(nskb)->daddr,
sizeof(struct tcphdr), IPPROTO_TCP,
csum_partial((char *)tcph,
csum_partial(tcph,
sizeof(struct tcphdr), 0));

nf_ct_attach(nskb, oldskb);
Expand Down
3 changes: 2 additions & 1 deletion net/ipv6/netfilter/ip6t_ah.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ match(const struct sk_buff *skb,
unsigned int protoff,
bool *hotdrop)
{
struct ip_auth_hdr *ah, _ah;
struct ip_auth_hdr _ah;
const struct ip_auth_hdr *ah;
const struct ip6t_ah *ahinfo = matchinfo;
unsigned int ptr;
unsigned int hdrlen = 0;
Expand Down
3 changes: 2 additions & 1 deletion net/ipv6/netfilter/ip6t_frag.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ match(const struct sk_buff *skb,
unsigned int protoff,
bool *hotdrop)
{
struct frag_hdr _frag, *fh;
struct frag_hdr _frag;
const struct frag_hdr *fh;
const struct ip6t_frag *fraginfo = matchinfo;
unsigned int ptr;
int err;
Expand Down
9 changes: 6 additions & 3 deletions net/ipv6/netfilter/ip6t_hbh.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,17 @@ match(const struct sk_buff *skb,
unsigned int protoff,
bool *hotdrop)
{
struct ipv6_opt_hdr _optsh, *oh;
struct ipv6_opt_hdr _optsh;
const struct ipv6_opt_hdr *oh;
const struct ip6t_opts *optinfo = matchinfo;
unsigned int temp;
unsigned int ptr;
unsigned int hdrlen = 0;
bool ret = false;
u8 _opttype, *tp = NULL;
u8 _optlen, *lp = NULL;
u8 _opttype;
u8 _optlen;
const u_int8_t *tp = NULL;
const u_int8_t *lp = NULL;
unsigned int optlen;
int err;

Expand Down
Loading

0 comments on commit a47362a

Please sign in to comment.