problem with dlil_inject_pr_output
I'm having a problem with the dlil_inject_pr_output function. At the base level, what I'm trying to do is intercept packets, copy them, and re-insert them via the dlil_inject_pr_input/output functions. In between the intercept and insert I will later add other features, but at this point I'm not changing the packet at all. When i intercept and re-inject incoming packets, I have no problems. However when i do the same process for outgoing packets, I have a couple of wierd problems: One is when I initiate a session from the OS X machine with my KEXT, an error occurs and the session terminates improperly. I watched the traffic using tcpdump and I get a SYN from the OS X machine, a SYN,ACK from the other machine, and the OS X machine responds to that with a RST. My other problem is when I initiate a session from a remote machine to the OS X machine with my KEXT, everything works until i terminate the session. With telnet, termination ends up in a loop where the OS X machine sends its final FIN, and the remote machine sends the ACK, then the OS X machine again sends that last FIN. The process that I use to re-inject packets is fairly straight forward. I copy the mbuf, sockaddr, frame type, and dest link address that are given to me via my filter_dl_output function. I use those copies and call the dlil_inject_pr_output function, then I return a -1 in the filter_dl_output function, so all the original data that I made copies of is freed. Both of these errors only occur when I intercept and re-inject packets on the output chain. I have verified that the problem is not in the input chain. The code for my filter_dl_output function is below: int slink_output(caddr_t cookie, struct mbuf **m, struct ifnet **ifp, struct sockaddr **dest, char *dest_linkaddr, char *frame_type) { char *ndla = NULL,*ipft = NULL; struct mbuf *mbf = NULL; struct sockaddr *nsa = NULL; if(*((uint16 *)frame_type) != IP_FRAME_TYPE) {// ignore non ip packets printf("slink_output: ignoring non-ip packet...\n"); return 0; } MALLOC(ndla,char *,MAC_ADDR_SIZE,M_CACHE,M_WAIT); if(ndla == NULL) { printf("slink_input: MALLOC, failure allocating space for dest_linkaddr...\n"); return SL_FAILURE; } bzero(ndla,MAC_ADDR_SIZE); bcopy(dest_linkaddr,ndla,MAC_ADDR_SIZE); MALLOC(ipft,char *,sizeof(uint16),M_CACHE,M_WAIT); if(ipft == NULL) { printf("slink_input: MALLOC, failure allocating space for frame_type...\n"); return SL_FAILURE; } bzero(ipft,sizeof(uint16)); bcopy(frame_type,ipft,sizeof(uint16)); MALLOC(nsa,struct sockaddr *,(*dest)->sa_len + 2,M_CACHE,M_WAIT); if(nsa == NULL) { printf("slink_input: MALLOC, failure allocating space for dest_sockaddr...\n"); return SL_FAILURE; } bzero(nsa,(*dest)->sa_len + 2); bcopy(*dest,nsa,(*dest)->sa_len + 2); mbf = m_copym(*m,0,M_COPYALL,M_WAIT); if((ret = dlil_inject_pr_output(mbf,nsa,FALSE,ipft,ndla,slink_hook_id)) != 0) printf("slink_output: dlil_inject_pr_output, failure, errno %d ...\n",ret); return -1; } _______________________________________________ darwin-kernel mailing list | darwin-kernel@lists.apple.com Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/darwin-kernel Do not post admin requests to the list. They will be ignored.
participants (1)
-
Hale, Darrian J