generate UDP checksum for hdr->check == 0x0

Discussion in 'Tomato Firmware' started by GoSPoS, Sep 1, 2011.

  1. GoSPoS

    GoSPoS Networkin' Nut Member

    I need to force my router (tomato 1.28 from git) to generate UDP checksum for UDP packets without checksum (value 0x0). to be more precise this is needed for RTP traffic coming from media gateway, which unfortunatelly is not capable of checksum generation (as well as SBC on the way).
    I found that checksum for UDP in NAT module are generated in: /tomato/release/src/linux/linux/net/ipv4/netfilter/ip_nat_proto_udp.c, in procedure:

    static void
    udp_manip_pkt(struct iphdr *iph, size_t len,
    const struct ip_conntrack_manip *manip,
    enum ip_nat_manip_type maniptype)
    struct udphdr *hdr = (struct udphdr *)((u_int32_t *)iph + iph->ihl);
    u_int32_t oldip;
    u_int16_t *portptr;

    if (maniptype == IP_NAT_MANIP_SRC) {
    /* Get rid of src ip and src pt */
    oldip = iph->saddr;
    portptr = &hdr->source;
    } else {
    /* Get rid of dst ip and dst pt */
    oldip = iph->daddr;
    portptr = &hdr->dest;
    if (hdr->check) /* 0 is a special case meaning no checksum */
    hdr->check = ip_nat_cheat_check(~oldip, manip->ip,
    ip_nat_cheat_check(*portptr ^ 0xFFFF,
    *portptr = manip->u.udp.port;

    I'm not great coder, especially with C, but I can see this is not real checksum procedure, but a kind of smart update, most likely to avoid performance issues. Also in this procedure we have an access only to headers, but not a payload, thus we can calculate brand new checksum.
    I do have a checksum procedure, but if anyone can tell me where I can put it.
    I don't care about performance, as this is only for lab purposes and in fact UDP with no checksum isn't very common thing (some VoIP systems).

    Can anyone help me with this?
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice