Nick Reilly
|
Re: Sample protocol LSM access and/or documentation
|
Nick Reilly
01/06/2014 10:39 AM
post107777
|
Re: Sample protocol LSM access and/or documentation
Hi Girish,
The complete networking source code is not available, but if you contact your sales representative they should be able
to give you access to the lsm-nraw.so source code. Also note that one alternative would be to use the BPF api.
Unfortunately we don't have too much documentation available for writing lsms, it is on our list of things to improve.
In your lsm you can use pfil to receive Ethernet frames. The init would be something like:
{
struct pfil_head *ether_pfil_hook;
ether_pfil_hook = pfil_head_get(PFIL_TYPE_IFT, IFT_ETHER);
if (ether_pfil_hook == NULL) {
return ENOENT;
}
rc = pfil_add_hook(your_input_fn, your_input_arg, PFIL_IN, ether_pfil_hook);
return rc;
}
Now this will get called on every Ethernet packet received.
int your_input_fn (void *your_input_arg, struct mbuf **mp, struct ifnet
*ifp, int dir)
{
struct mbuf *m;
m = *mp;
if (packet of interest) {
handle_it();
m_freem(m);
*mp = NULL;
return 1;
} else {
/* Let io-pkt handle it */
return 0;
}
}
For transmit you can also do:
ifp->if_output(ifp, m, &edst, 0);
This has an mbuf in m and edst is a struct sockaddr with
edst.sa_family = AF_UNSPEC;
edst.sa_data = struct ether_header data
m should just be the data in the frame, no header.
|
|
|