Re: [RTnet-developers] SOCKET RAW
Brought to you by:
bet-frogger,
kiszka
|
From: Jan K. <jan...@we...> - 2006-08-28 15:49:23
|
Jorge Almeida wrote: > Jan, >=20 > In attach i send you a diff file regarding the af_packet.c file where t= he RAW=20 > SOCKET is implemented, similar to the DGRAM SOCKET. Two general remarks, rest inlined below: o The diff parameter "-p" makes the output more readable by adding the context of the change. o Please avoid // comments (maybe except for temporary debug stuff) >=20 > I've already run some tests on it and everything looks OK. >=20 > Please run some more, or ask to (to some other interested person) and p= ublish=20 > the results. >=20 Do you have some test program? May an enhanced version of the existing packet-socket demo with selectable mode? Would make it easier to start. >=20 > Now i'm starting with the ETH_P_ALL to the protocol definition. > Were, in the code, can i start to see the protocol filter implementatio= n? > And wath is the best thing to do regarding ETH_P_ALL? Remove from QUEUE= or=20 > copy the message from buffer and it still remains there? The second has= the=20 > problem of the queue grows undefined.=20 > Any suggestions? See my earlier post: http://www.mail-archive.com/rtnet-users%40lists.sourceforge.net/msg01279.= html This would make ETH_P_ALL not true ALL, but it would also not blow up the current strict resource management scheme. Unless you are building a packet sniffer, this should be fine for most use cases (and there is already a sniffer interface). >=20 >=20 > Thanks >=20 >=20 >=20 > -----------------------------------------------------------------------= - >=20 > --- rtnet-0.9.4/stack/packet/af_packet.c 2006-08-06 19:23:36.000000000 = +0100 > +++ rtnet-0.9.4/stack/packet/af_packet.c 2006-08-28 16:07:35.000000000 = +0100 > @@ -89,7 +89,7 @@ > =20 > rtdm_lock_get_irqsave(&sock->param_lock, context); > =20 > - /* release exisiting binding */ > + /* release existing binding */ > if ((pt->type !=3D 0) && ((ret =3D rtdev_remove_pack(pt)) < 0)) { > rtdm_lock_put_irqrestore(&sock->param_lock, context); > return ret; > @@ -277,7 +277,7 @@ > /* non-blocking receive? */ > if (testbits(msg_flags, MSG_DONTWAIT)) > timeout =3D -1; > - > +// rt_printk("Packet:DEBUG: timeout %lld \n",timeout); > ret =3D rtdm_sem_timeddown(&sock->pending_sem, timeout, NULL); > if (unlikely(ret < 0)) { > if ((ret !=3D -EWOULDBLOCK) && (ret !=3D -ETIMEDOUT)) > @@ -313,10 +313,45 @@ > copy_len =3D len; > msg->msg_flags |=3D MSG_TRUNC; > } > + =20 > + if(sockctx->device->socket_type =3D=3D SOCK_DGRAM) > + { > +// rt_printk("Packet:DEBUG: SOCKET DGRAM SELECTED\n"); > + /* copy the data */ > + rt_memcpy_tokerneliovec(msg->msg_iov, skb->data, copy_len); > + } > + else if (sockctx->device->socket_type =3D=3D SOCK_RAW) > + { > + int nBufferLen =3D 0; > + int nI =3D 0; > + unsigned char puchBuffer[ETH_FRAME_LEN] =3D {0}; > + =20 > + memcpy((puchBuffer+nBufferLen), eth->h_dest,ETH_ALEN); > + nBufferLen +=3D ETH_ALEN; > =20 > - /* copy the data */ > - rt_memcpy_tokerneliovec(msg->msg_iov, skb->data, copy_len); > + memcpy((puchBuffer+nBufferLen), eth->h_source,ETH_ALEN); > + nBufferLen +=3D ETH_ALEN; > + > + memcpy((puchBuffer+nBufferLen), &(eth->h_proto),2); > + nBufferLen +=3D 2; > =20 > + memcpy((puchBuffer+nBufferLen), skb->data, copy_len); > + nBufferLen +=3D copy_len; > + /* start DEBUG purpouse*/ > +// rt_printk("Message Received: "); > +// for(nI =3D 0; nI <nBufferLen ; nI++) > +// rt_printk(" %02X",puchBuffer[nI]); > +// rt_printk("\n"); > + /* end DEBUG purpouse*/ > + /* copy the data to user */ =20 > + rt_memcpy_tokerneliovec(msg->msg_iov, puchBuffer, nBufferLen);= > + /* new buffer length*/ > + real_len =3D nBufferLen; > + } > + else > + { > + rt_printk("Packet: Socket type Not Supported\n"); > + } > if ((msg_flags & MSG_PEEK) =3D=3D 0) { > rtdev_dereference(skb->rtdev); > kfree_rtskb(skb); > @@ -383,12 +418,38 @@ > =20 > rtskb->rtdev =3D rtdev; > rtskb->priority =3D sock->priority; > - > - if (rtdev->hard_header) { > - ret =3D rtdev->hard_header(rtskb, rtdev, ntohs(sll->sll_protoc= ol), > - sll->sll_addr, rtdev->dev_addr, rtskb= ->len); > - if (ret < 0) > - goto err; > + // SOCK_DGRAM > + if(sockctx->device->socket_type =3D=3D SOCK_DGRAM) > + { > +// rt_printk("Packet:DEBUG: SOCKET DGRAM SELECTED\n"); > + =20 > + if (rtdev->hard_header) { > + ret =3D rtdev->hard_header(rtskb, rtdev, ntohs(sll->sll_pr= otocol), > + sll->sll_addr, rtdev->dev_addr, rt= skb->len); > + if (ret < 0) > + goto err; > + } > + } > + // SOCK_RAW > + else if (sockctx->device->socket_type =3D=3D SOCK_RAW) > + { > +// rt_printk("Packet:DEBUG: SOCKET RAW SELECTED\n"); > + unsigned char puchBuffer[ETH_FRAME_LEN]; > + =20 > + if (rtdev->hard_header) { > + ret =3D rtdev->hard_header(rtskb, rtdev, (rtskb->data+ETH_= ALEN+ETH_ALEN), > + sll->sll_addr, (rtskb->data+ETH_A= LEN), (rtskb->len - ETH_HLEN)); > + if (ret < 0) > + goto err; > + } > + memcpy(puchBuffer,rtskb->data,rtskb->len); > + memcpy(rtskb->data,(puchBuffer+ETH_HLEN),(rtskb->len - ETH_HLE= N)); > + rtskb->len =3D rtskb->len - ETH_HLEN; > +// rt_printk("Packet:DEBUG: SOCKET RAW SELECTED and exit\n"); > + } > + else > + { > + rt_printk("Packet: Socket type Not Supported\n"); This is debug output, isn't it? If you get here, you did something wrong during socket setup. That would also simplify the test above to if (...socket_type =3D=3D SOCK_DGRAM) { } else { }. > } > =20 > if ((rtdev->flags & IFF_UP) !=3D 0) { > @@ -409,8 +470,6 @@ > return ret; > } > =20 > - > - > static struct rtdm_device packet_proto_dev =3D { > struct_version: RTDM_DEVICE_STRUCT_VER, > =20 > @@ -430,7 +489,7 @@ > ioctl_nrt: rt_packet_ioctl, > recvmsg_rt: rt_packet_recvmsg, > sendmsg_rt: rt_packet_sendmsg > - }, > +}, > =20 > device_class: RTDM_CLASS_NETWORK, > device_sub_class: RTDM_SUBCLASS_RTNET, > @@ -443,15 +502,55 @@ > }; > =20 > =20 > +static struct rtdm_device raw_packet_proto_dev =3D { > + struct_version: RTDM_DEVICE_STRUCT_VER, > + > + device_flags: RTDM_PROTOCOL_DEVICE, > + context_size: sizeof(struct rtsocket), > + > + protocol_family: PF_PACKET, > + socket_type: SOCK_RAW, > + > + socket_rt: rt_packet_socket, > + socket_nrt: rt_packet_socket, > + > + ops: { > + close_rt: rt_packet_close, > + close_nrt: rt_packet_close, > + ioctl_rt: rt_packet_ioctl, > + ioctl_nrt: rt_packet_ioctl, > + recvmsg_rt: rt_packet_recvmsg, > + sendmsg_rt: rt_packet_sendmsg > + }, > + > + device_class: RTDM_CLASS_NETWORK, > + device_sub_class: RTDM_SUBCLASS_RTNET, > + driver_name: "rtrawpacket", Driver name is still "rtpacket" (same binary). > + driver_version: RTNET_RTDM_VER, > + peripheral_name: "Real-Time Packet Socket Interface", > + provider_name: rtnet_rtdm_provider_name, > + > + proc_name: "PACKET_RAW" > +}; > + > + > int __init rt_packet_proto_init(void) > { > - return rtdm_dev_register(&packet_proto_dev); > + int nReturn =3D -1; > + nReturn =3D rtdm_dev_register(&packet_proto_dev); > + if(nReturn !=3D 0) > + return nReturn; > +// rt_printk("DGRAM return =3D %d\n",nReturn); > + nReturn =3D rtdm_dev_register(&raw_packet_proto_dev); > +// rt_printk("RAW return =3D %d\n",nReturn); > + return nReturn; Mmh, and what happens to the packet_proto_dev registration if raw_packet_proto_dev goes South? > } > =20 > =20 > void rt_packet_proto_release(void) > { > rtdm_dev_unregister(&packet_proto_dev, 1000); > + rtdm_dev_unregister(&raw_packet_proto_dev, 1000); > } > =20 > =20 Thanks for your contribution! Jan |