problems with modifying payload in iff_input_func
problems with modifying payload in iff_input_func
- Subject: problems with modifying payload in iff_input_func
- From: Andy Huang <email@hidden>
- Date: Thu, 13 May 2010 14:35:07 -0500
Hi,
I am trying to modify enetlognke NKE, and in it I try to modify the payload
inside enet_input_func(iff_input_
func). Here is my code:
static
errno_t
enet_input_func(void* cookie, ifnet_t interface,
protocol_family_t protocol,
mbuf_t *data, char **frame_ptr)
{
mbuf_t m = *data;
u_int32_t mbufs = 0, bytes = 0,
ip_hdr_len = 0, ip_pkt_len = 0;
errno_t err;
struct
ip ip_hdr, *pIpHdr;
char buf[BUF_SIZE];
/* check whether we have seen this
packet previously */
if (CheckTag(*data, INBOUND_DONE))
{
/* we have
processed this packet previously since the INBOUND_DONE bit was set.
bail on further processing
*/
return 0;
}
if (protocol !=
AF_INET)
{
//printf("protocol = %d, don't process it\n", protocol);
return 0;
}
err = SetTag(*data, INBOUND_DONE);
if (err !=
0)
{
printf("Error - mbuf_tag_allocate returned an error
%d\n", err);
return err; // stops processing and will
cause the mbuf_t to be released
}
do
{
mbufs++;
bytes +=
mbuf_len(m);
m = mbuf_next(m);
} while (m != NULL);
if (bytes < BUF_SIZE) // BUF_SIZE is the size of 4096
{
printf("bytes(%d) < BUF_SIZE, don't process it\n",
bytes);
return 0;
}
err =
mbuf_copydata(*data, 0, bytes, buf);
if
(err != 0)
{
printf("Error - mbuf_copydata failed\n");
return 0;
}
// modify the payload in the buf
..........
// copy back
err =
mbuf_copyback(*data, 0, bytes, buf, MBUF_DONTWAIT);
if (err != 0)
{
printf("Error - mbuf_copyback for
%d bytes returned an error %d\n", bytes, err);
return err;
}
return 0;
}
The code works most of the time. But when the mac (10.6.3) goes to sleep
and then wake up, after a while, it goes to either freeze or panic.
Any
help will be
greatly appreciated.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-kernel mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden