Skip to contentSkip to conversation

netpoll.c unaligned access

PATCH In review Benoit Welterlen 2 participants 2 messages Jun 24, 2004

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 netpoll.c unaligned access

Hello,

I use netpoll (net/core/netpoll.c) to send dump over the network on IA64 (LKCD). But I have "unaligned access" in the netpoll_send_udp function. I rewrited it to avoid this message :

------------------------------------------------------------------------
void netpoll_send_udp(struct netpoll *np, const char *msg, int len)

{
	int total_len, eth_len, ip_len, udp_len;
	struct sk_buff *skb;
	struct udphdr *udph;
	struct iphdr *iph;
	struct ethhdr *eth;

	udp_len = len + sizeof(*udph);
	ip_len = eth_len = udp_len + sizeof(*iph);
	total_len = eth_len + ETH_HLEN;

	skb = find_skb(np, total_len, total_len - len);
	if (!skb)
		return;

	memcpy(skb->data, msg, len);
	skb->len += len;

	udph = (struct udphdr *) skb_push(skb, sizeof(*udph));
	udph->source = htons(np->local_port);
	udph->dest = htons(np->remote_port);
	udph->len = htons(udp_len);
	udph->check = 0;

	iph = (struct iphdr *)skb_push(skb, sizeof(*iph));
#if defined(__LITTLE_ENDIAN_BITFIELD)
	//iph->ihl      = 5; iph->version  = 4;
	put_unaligned(0x45,(unsigned char *)iph);
#elif defined (__BIG_ENDIAN_BITFIELD) 
        //iph->version  = 4; iph->ihl      = 5;
	put_unaligned(0x54,(unsigned char *)iph);
#else
#error	"Please fix <asm/byteorder.h>"
#endif
	iph->tos      = 0;
	put_unaligned(htons(ip_len),&(iph->tot_len));
	iph->id       = 0;
	iph->frag_off = 0;
	iph->ttl      = 64;
	iph->protocol = IPPROTO_UDP;
	iph->check    = 0;
	put_unaligned(htonl(np->local_ip),&(iph->saddr));
	put_unaligned(htonl(np->remote_ip),&(iph->daddr));
	iph->check    = ip_fast_csum((unsigned char *)iph, 5);

	eth = (struct ethhdr *) skb_push(skb, ETH_HLEN);

	eth->h_proto = htons(ETH_P_IP);
	memcpy(eth->h_source, np->local_mac, 6);
	memcpy(eth->h_dest, np->remote_mac, 6);

	netpoll_send_skb(np, skb);
}

-----------------------------------------------------------------

Regards,

Benoit Welterlen

Signature · 11 lines
*************************************************
*						*
*  .,p**"*=b_  Benoit Welterlen Welty		*
* ?P"  .__ `*b   BULL SA Echirolles (France)	*
* |P  .d?'`&, 9|   Room : B1 - 405 		*	
* M:  |}   |- H'   Tel : 0 47629 7390		*
* &|  `#?_._oH'  Linux Kernel Team		*
* `H.   "`"`'   				*
*  `#?.      					*
*    `^~.					*
*************************************************

begin:vcard
n:Welterlen;Benoit
x-mozilla-html:TRUE
org:Bull SA;Linux Kernel
adr:;;;;;;
version:2.1
email;internet:[email protected]
title:Stagiaire
note;quoted-printable:Polytech`Grenoble=0D=0A------------------------------=0D=0A"Software is like sex it's better when it's free.", Linus Torvalds x-mozilla-cpt:;-5920
fn:Benoit Welterlen
end:vcard

#1 lore raw
Quoted 3 lines · Benoit Welterlen

I use netpoll (net/core/netpoll.c) to send dump over the network on IA64 (LKCD). But I have "unaligned access" in the netpoll_send_udp function. I rewrited it to avoid this message :

Please read Documentation/SubmittingPatches (in the Linux kernel source tree) and post a patch (output of "diff -u") as outlined there.