From owner-freebsd-net Wed Apr 4 4: 7:14 2001 Delivered-To: freebsd-net@freebsd.org Received: from mss.rdc2.nsw.optushome.com.au (ha1.rdc2.nsw.optushome.com.au [203.164.2.50]) by hub.freebsd.org (Postfix) with ESMTP id 78ABF37B71C for ; Wed, 4 Apr 2001 04:07:10 -0700 (PDT) (envelope-from s2209866@cse.unsw.edu.au) Received: from co3038206a ([203.164.177.110]) by mss.rdc2.nsw.optushome.com.au (InterMail vM.4.01.03.20 201-229-121-120-20010223) with SMTP id <20010404110709.YLII17266.mss.rdc2.nsw.optushome.com.au@co3038206a> for ; Wed, 4 Apr 2001 21:07:09 +1000 Reply-To: From: "Daniel Wong" To: Subject: how to generate a custom ICMP packet from kernel ?? Date: Wed, 4 Apr 2001 21:07:49 +1000 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2910.0) X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 Importance: Normal Sender: owner-freebsd-net@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org 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