Git Product home page Git Product logo

Comments (4)

sbernard31 avatar sbernard31 commented on September 21, 2024

Hi, maybe RFC1624 - Computation of the Internet Checksum via Incremental Update could help you ?

from sbulb.

iGwkang avatar iGwkang commented on September 21, 2024

Hi, maybe RFC1624 - Computation of the Internet Checksum via Incremental Update could help you ?

@sbernard31

Hi, I wrote a function to update the udp checksum according to the formula HC' = HC - ~m - m' in RFC1624, but it is still wrong, can you help me?
thanks

typedef union {
  struct {
    u16 ip1;
    u16 ip2;
  };
  u32 ip;
} ip_num;

static __always_inline void udp_checksum_update(struct iphdr *old_iph, struct iphdr *iph, struct udphdr *old_udp, struct udphdr *udph)
{
  // ip
  ip_num old_src_ip, new_src_ip, old_dst_ip, new_dst_ip;
  old_src_ip.ip = old_iph->saddr;
  new_src_ip.ip = iph->saddr;
  old_dst_ip.ip = old_iph->daddr;
  new_dst_ip.ip = iph->daddr;

  // port
  u16 old_src_port = old_udp->source, new_src_port = udph->source;
  u16 old_dst_port = old_udp->dest, new_dst_port = udph->dest;

  // calc checksum
  u16 new_csum = old_udp->check;

  // src ip
  new_csum = new_csum - (~old_src_ip.ip1) - new_src_ip.ip1;
  new_csum = new_csum - (~old_src_ip.ip2) - new_src_ip.ip2;
  // dest ip
  new_csum = new_csum - (~old_dst_ip.ip1) - new_dst_ip.ip1;
  new_csum = new_csum - (~old_dst_ip.ip2) - new_dst_ip.ip2;

  // src port
  new_csum = new_csum - (~old_src_port) - new_src_port;

  // dest port
  new_csum = new_csum - (~old_dst_port) - new_dst_port;
  
  udph->check = new_csum;
}

from sbulb.

sbernard31 avatar sbernard31 commented on September 21, 2024

Did you also looked at : https://github.com/AirVantage/sbulb/blob/master/sbulb/bpf/checksum.c

from sbulb.

iGwkang avatar iGwkang commented on September 21, 2024

Did you also looked at : master/sbulb/bpf/checksum.c

@sbernard31 thanks
I misunderstood this function before, thinking that this function restricted u32, now my code has been changed to the following, and the verification has passed.

static __always_inline void udp_checksum_update(struct iphdr *old_iph, struct iphdr *iph, struct udphdr *old_udp, struct udphdr *udph)
{
  u16 new_csum = old_udp->check;
  update_csum(&new_csum, old_iph->saddr, iph->saddr);
  update_csum(&new_csum, old_iph->daddr, iph->daddr);
  update_csum(&new_csum, old_udp->source, udph->source);
  update_csum(&new_csum, old_udp->dest, udph->dest);
  udph->check = new_csum;
  return;
}

from sbulb.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.