리눅스 디바이스 드라이버에서 arp 를 보내다 질문 드립니다.
글쓴이: dicecorp / 작성시간: 수, 2009/09/02 - 3:11오후
디바이스 드라이버에서 arp 를 전송하려고 합니다.
arp 패킷 구조를 보니까
|<--------->|<-------->|<--->|<--------->|<-------->|
dst mac src mac type data crc
(6) (6) (2) (46-1500) (4)
위와 같이 구성이 되어 있더군요
질문 1.
arp 패킷의 최소 크기가 60 이 맞는지요? 다른 곳에 있는 코드를 참조하니까 60 이상일 경우 60 을 넣고 있길래 그 코드를 참조했습니다.
위 그림을 참조했을때 crc를 뺐을 경우 60이 나오네요
질문 2.
sk_buff->data 멤버에 위의 dst mac 부터 data까지 들어가는지요?
따라서 size는 60 이 되는게 맞는지 궁금합니다.
질문 3.
crc 는 dst mac 부터 data까지 구하는 것인지요?
* 참고로 아래코드의 브로드캐스트 맥 주소의
{0xff, 0x00, 0xff, 0xff, 0xff, 0xff}; 두 번째 필드를 0xff 로 했습니다.
이유는 패킷이 나가는 지 보기 위해서입니다. (참고로 무선랜입니다.)
struct arp_data{ unsigned char ar_sha[ETH_ALEN];//sender HW addr unsigned long ar_sip; //sender IP addr unsigned char ar_tha[ETH_ALEN];//target HW addr unsigned long ar_tip; //target IP addr }__attribute__((packed)); struct sk_buff *skb; struct arp_data *arp_request; int size; unsigned char sum_crc; unsigned char broadcast_mac[6] = {0xff, 0x00, 0xff, 0xff, 0xff, 0xff}; // arp packet send size = 2 * ETH_ALEN + 2 + sizeof(struct arphdr) + sizeof(struct arp_data) + 4; if (size < 60) size = 60; if( (skb = dev_alloc_skb(size)) == NULL){ printk("_SDBG_ dev alloc failed\n"); return ; } skb->mac.ethernet = (struct ethhdr *)skb->data; skb->dev = priv->dev; skb->len = size; skb->protocol = htons(ETH_P_ARP); memcpy(skb->mac.ethernet->h_dest, broadcast_mac, ETH_ALEN); //h_dest memcpy(skb->mac.ethernet->h_source, priv->dev->dev_addr, ETH_ALEN);//h_source skb->mac.ethernet->h_proto = ETH_P_ARP; //h_proto skb->nh.arph = (struct arphdr*)(skb->data + sizeof(struct ethhdr)); skb->nh.arph->ar_hrd = ARPHRD_ETHER; skb->nh.arph->ar_pro = EHT_P_IP; skb->nh.arph->ar_hln = 0x06; skb->nh.arph->ar_pln = 0x04; skb->nh.arph->ar_op = ARPOP_REQUEST; sum_crc = byte-check_sum(skb->data, size); skb->data[size -4] = sum_crc; dev_queue_xmit(skb);
Forums:
http://lxr.linux.no/linux+v2.
http://lxr.linux.no/linux+v2.6.30.5/net/ipv4/arp.c#L672
OTL
댓글 달기