icmp.asm


#define ICMP_TYPE   (IPD+0)
#define ICMP_CODE   (ICMP_TYPE+1)
#define ICMP_CHK    (ICMP_CODE+1)
#define ICMP_UNUSED (ICMP_CHK+2)
#define ICMP_IPH    (ICMP_UNUSED+4)
//
// IH biases the base offset of the headers that are included in an ICMP
// "unreachable port" message so that we can add the canonical packet
// offsets to pick the individual fields.
//
#define IH (ICMP_IPH-(IPH))

;+
; **-my_icmp-icmp frame received.
;
; outputs:
;   flow-through pcode
;-
    .global import_unknown_icmp
import_unknown_icmp:
    pbegin
    pr2s buf,ICMP_TYPE,2
    pcmpwi buf,0x0303               ; unreachable port
    pjumpne 99f

    pr2s buf,IH+IP_TTLP,2           ; get TTL/PROTO
    pcmpbi buf+1,0x11               ; check if UDP
    pjumpne 99f                     ; no - ignore

    pr2s buf,IH+IP_SRCADDR,4        ; get source
    pcmp4 buf,my_ip                 ; is it mine?
    pjumpne 99f                     ; no - ignore this noise

    pr2s buf,IH+IP_DSTADDR,4        ; get destination
    pcall icmp_test_destaddr        ; check against user-specified address
    pjumpne 99f                     ; no - more noise

    pr2s buf,IH+UDP_DP,2
    pcall udp_port_unreachable
99:
    pasmret

Back