提交 375d9d71 编写于 作者: S Steven Whitehouse 提交者: David S. Miller

[DECNET]: Endianess fixes (try #2)

Here are some fixes to endianess problems spotted by Al Viro.
Signed-off-by: NSteven Whitehouse <swhiteho@redhat.com>
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
上级 af2c6a4a
...@@ -166,7 +166,7 @@ static struct hlist_head *dn_find_list(struct sock *sk) ...@@ -166,7 +166,7 @@ static struct hlist_head *dn_find_list(struct sock *sk)
if (scp->addr.sdn_flags & SDF_WILD) if (scp->addr.sdn_flags & SDF_WILD)
return hlist_empty(&dn_wild_sk) ? &dn_wild_sk : NULL; return hlist_empty(&dn_wild_sk) ? &dn_wild_sk : NULL;
return &dn_sk_hash[scp->addrloc & DN_SK_HASH_MASK]; return &dn_sk_hash[dn_ntohs(scp->addrloc) & DN_SK_HASH_MASK];
} }
/* /*
...@@ -180,7 +180,7 @@ static int check_port(__le16 port) ...@@ -180,7 +180,7 @@ static int check_port(__le16 port)
if (port == 0) if (port == 0)
return -1; return -1;
sk_for_each(sk, node, &dn_sk_hash[port & DN_SK_HASH_MASK]) { sk_for_each(sk, node, &dn_sk_hash[dn_ntohs(port) & DN_SK_HASH_MASK]) {
struct dn_scp *scp = DN_SK(sk); struct dn_scp *scp = DN_SK(sk);
if (scp->addrloc == port) if (scp->addrloc == port)
return -1; return -1;
...@@ -194,12 +194,12 @@ static unsigned short port_alloc(struct sock *sk) ...@@ -194,12 +194,12 @@ static unsigned short port_alloc(struct sock *sk)
static unsigned short port = 0x2000; static unsigned short port = 0x2000;
unsigned short i_port = port; unsigned short i_port = port;
while(check_port(++port) != 0) { while(check_port(dn_htons(++port)) != 0) {
if (port == i_port) if (port == i_port)
return 0; return 0;
} }
scp->addrloc = port; scp->addrloc = dn_htons(port);
return 1; return 1;
} }
...@@ -418,7 +418,7 @@ struct sock *dn_find_by_skb(struct sk_buff *skb) ...@@ -418,7 +418,7 @@ struct sock *dn_find_by_skb(struct sk_buff *skb)
struct dn_scp *scp; struct dn_scp *scp;
read_lock(&dn_hash_lock); read_lock(&dn_hash_lock);
sk_for_each(sk, node, &dn_sk_hash[cb->dst_port & DN_SK_HASH_MASK]) { sk_for_each(sk, node, &dn_sk_hash[dn_ntohs(cb->dst_port) & DN_SK_HASH_MASK]) {
scp = DN_SK(sk); scp = DN_SK(sk);
if (cb->src != dn_saddr2dn(&scp->peer)) if (cb->src != dn_saddr2dn(&scp->peer))
continue; continue;
...@@ -1016,13 +1016,14 @@ static void dn_access_copy(struct sk_buff *skb, struct accessdata_dn *acc) ...@@ -1016,13 +1016,14 @@ static void dn_access_copy(struct sk_buff *skb, struct accessdata_dn *acc)
static void dn_user_copy(struct sk_buff *skb, struct optdata_dn *opt) static void dn_user_copy(struct sk_buff *skb, struct optdata_dn *opt)
{ {
unsigned char *ptr = skb->data; unsigned char *ptr = skb->data;
u16 len = *ptr++; /* yes, it's 8bit on the wire */
opt->opt_optl = *ptr++;
opt->opt_status = 0; BUG_ON(len > 16); /* we've checked the contents earlier */
memcpy(opt->opt_data, ptr, opt->opt_optl); opt->opt_optl = dn_htons(len);
skb_pull(skb, dn_ntohs(opt->opt_optl) + 1); opt->opt_status = 0;
memcpy(opt->opt_data, ptr, len);
skb_pull(skb, len + 1);
} }
static struct sk_buff *dn_wait_for_connect(struct sock *sk, long *timeo) static struct sk_buff *dn_wait_for_connect(struct sock *sk, long *timeo)
......
...@@ -360,9 +360,9 @@ static void dn_nsp_conn_conf(struct sock *sk, struct sk_buff *skb) ...@@ -360,9 +360,9 @@ static void dn_nsp_conn_conf(struct sock *sk, struct sk_buff *skb)
scp->max_window = decnet_no_fc_max_cwnd; scp->max_window = decnet_no_fc_max_cwnd;
if (skb->len > 0) { if (skb->len > 0) {
unsigned char dlen = *skb->data; u16 dlen = *skb->data;
if ((dlen <= 16) && (dlen <= skb->len)) { if ((dlen <= 16) && (dlen <= skb->len)) {
scp->conndata_in.opt_optl = dn_htons((__u16)dlen); scp->conndata_in.opt_optl = dn_htons(dlen);
memcpy(scp->conndata_in.opt_data, skb->data + 1, dlen); memcpy(scp->conndata_in.opt_data, skb->data + 1, dlen);
} }
} }
...@@ -404,9 +404,9 @@ static void dn_nsp_disc_init(struct sock *sk, struct sk_buff *skb) ...@@ -404,9 +404,9 @@ static void dn_nsp_disc_init(struct sock *sk, struct sk_buff *skb)
memset(scp->discdata_in.opt_data, 0, 16); memset(scp->discdata_in.opt_data, 0, 16);
if (skb->len > 0) { if (skb->len > 0) {
unsigned char dlen = *skb->data; u16 dlen = *skb->data;
if ((dlen <= 16) && (dlen <= skb->len)) { if ((dlen <= 16) && (dlen <= skb->len)) {
scp->discdata_in.opt_optl = dn_htons((__u16)dlen); scp->discdata_in.opt_optl = dn_htons(dlen);
memcpy(scp->discdata_in.opt_data, skb->data + 1, dlen); memcpy(scp->discdata_in.opt_data, skb->data + 1, dlen);
} }
} }
......
...@@ -526,7 +526,7 @@ void dn_send_conn_conf(struct sock *sk, gfp_t gfp) ...@@ -526,7 +526,7 @@ void dn_send_conn_conf(struct sock *sk, gfp_t gfp)
struct nsp_conn_init_msg *msg; struct nsp_conn_init_msg *msg;
__u8 len = (__u8)dn_ntohs(scp->conndata_out.opt_optl); __u8 len = (__u8)dn_ntohs(scp->conndata_out.opt_optl);
if ((skb = dn_alloc_skb(sk, 50 + dn_ntohs(scp->conndata_out.opt_optl), gfp)) == NULL) if ((skb = dn_alloc_skb(sk, 50 + len, gfp)) == NULL)
return; return;
msg = (struct nsp_conn_init_msg *)skb_put(skb, sizeof(*msg)); msg = (struct nsp_conn_init_msg *)skb_put(skb, sizeof(*msg));
......
...@@ -124,8 +124,8 @@ static struct nla_policy dn_fib_rule_policy[FRA_MAX+1] __read_mostly = { ...@@ -124,8 +124,8 @@ static struct nla_policy dn_fib_rule_policy[FRA_MAX+1] __read_mostly = {
static int dn_fib_rule_match(struct fib_rule *rule, struct flowi *fl, int flags) static int dn_fib_rule_match(struct fib_rule *rule, struct flowi *fl, int flags)
{ {
struct dn_fib_rule *r = (struct dn_fib_rule *)rule; struct dn_fib_rule *r = (struct dn_fib_rule *)rule;
u16 daddr = fl->fld_dst; __le16 daddr = fl->fld_dst;
u16 saddr = fl->fld_src; __le16 saddr = fl->fld_src;
if (((saddr ^ r->src) & r->srcmask) || if (((saddr ^ r->src) & r->srcmask) ||
((daddr ^ r->dst) & r->dstmask)) ((daddr ^ r->dst) & r->dstmask))
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册