Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 4 Apr 2001 21:07:49 +1000
From:      "Daniel Wong" <s2209866@cse.unsw.edu.au>
To:        <freebsd-net@freeBSD.ORG>
Subject:   how to generate a custom ICMP packet from kernel ??
Message-ID:  <NDBBJCEECLLLJHEBJOGDCELIEOAA.s2209866@cse.unsw.edu.au>

next in thread | raw e-mail | index | archive | help
Hi,

I've set up my own ICMP type - type 40 (ICMP_PROBE) which is to be used for
probing the network's conjestion etc... (don't want to bore you with
details) anyways... I've tried to imitate the way that icmp_error generates
and icmp packet, but I have no idea why it's not sending... below is the
piece of code I'm building the icmp packet with. If you can find anything
wrong with it (it maybe to do with the offset ?) or know why it might not be
able to pass through the ip_output, please please please help me solve this
problem! I pass in three arguments:

mbuf *m; /* the memory buffer of the a packet for a particular flow of which
I'm inspecting*/

dport and sport ar the destination and source ports of the flow

it all compiles and runs without interferring with normal flow of packets.

/***** starts here _________________  ip_icmp.c _______******/
void
icmp_sendprobe( m, dport, sport )
 struct mbuf *m;
 u_short dport;
 u_short sport;
{
 struct mbuf *nbuf, *opts = 0;
 struct icmp *icp;
 struct ip  *oip, *nip;

 oip = mtod(m, struct ip *);
 nbuf = m_gethdr(M_DONTWAIT, MT_HEADER);
 if (nbuf == NULL) {
  printf("Probe not created!");
  return;
 }
 nbuf->m_len = ICMP_PRBLEN;
 MH_ALIGN(nbuf, nbuf->m_len);
 icp = mtod(nbuf, struct icmp *);
 icp->icmp_type = ICMP_PROBE;
 icp->icmp_code = 0;

 /* setting up probe */
 icp->icmp_pmdst = dport;
 icp->icmp_pmsrc = sport;

 /* zero out flow information */
 icp->icmp_pm_flowinfo = 0;
 icp->icmp_pm_dir = ICMP_PM_DIR_FWD;

 if (nbuf->m_data - sizeof(struct ip) < nbuf->m_pktdat)
  panic("icmp_probe len");

 /* moved the data pointer upwards */
 nbuf->m_data -= sizeof(struct ip);

 /* increase the length of the packet */
 nbuf->m_len += sizeof(struct ip);
 nbuf->m_pkthdr.len = nbuf->m_len;

 /* set the receive interface */
 nbuf->m_pkthdr.rcvif = m->m_pkthdr.rcvif;

 nip = mtod(nbuf, struct ip *);

 /* copy the tcp/udp packet's IP header */
 bcopy((caddr_t)oip, (caddr_t)nip, sizeof(struct ip));
 nip->ip_len = nbuf->m_len;

 nip->ip_vhl = IP_VHL_BORING;
 nip->ip_p = IPPROTO_ICMP;
 nip->ip_tos = 0;
 nip->ip_ttl = MAXTTL;

 nbuf->m_flags &= ~(M_BCAST|M_MCAST);

 icmp_send( nbuf, opts );
}
/**** ends here ____________________  ip_icmp.c ______*****/

icmp_send unchanged and used to send the packet out

Regards
Dan


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-net" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?NDBBJCEECLLLJHEBJOGDCELIEOAA.s2209866>