]> git.proxmox.com Git - mirror_frr.git/blobdiff - lib/checksum.c
lib: fix doc comment of the "cli_show_end" northbound callback
[mirror_frr.git] / lib / checksum.c
index 8eef73e2435feed953c067dab46016f82dcc9633..34733700417f1f3020df37dc71aab0e1957129ff 100644 (file)
 int /* return checksum in low-order 16 bits */
        in_cksum(void *parg, int nbytes)
 {
-       u_short *ptr = parg;
+       unsigned short *ptr = parg;
        register long sum; /* assumes long == 32 bits */
-       u_short oddbyte;
-       register u_short answer; /* assumes u_short == 16 bits */
+       unsigned short oddbyte;
+       register unsigned short answer; /* assumes unsigned short == 16 bits */
 
        /*
         * Our algorithm is simple, using a 32-bit accumulator (sum),
@@ -32,7 +32,7 @@ int /* return checksum in low-order 16 bits */
        /* mop up an odd byte, if necessary */
        if (nbytes == 1) {
                oddbyte = 0; /* make sure top half is zero */
-               *((u_char *)&oddbyte) = *(u_char *)ptr; /* one byte only */
+               *((uint8_t *)&oddbyte) = *(uint8_t *)ptr; /* one byte only */
                sum += oddbyte;
        }
 
@@ -46,6 +46,24 @@ int /* return checksum in low-order 16 bits */
        return (answer);
 }
 
+int in_cksum_with_ph4(struct ipv4_ph *ph, void *data, int nbytes)
+{
+       uint8_t dat[sizeof(struct ipv4_ph) + nbytes];
+
+       memcpy(dat, ph, sizeof(struct ipv4_ph));
+       memcpy(dat + sizeof(struct ipv4_ph), data, nbytes);
+       return in_cksum(dat, sizeof(dat));
+}
+
+int in_cksum_with_ph6(struct ipv6_ph *ph, void *data, int nbytes)
+{
+       uint8_t dat[sizeof(struct ipv6_ph) + nbytes];
+
+       memcpy(dat, ph, sizeof(struct ipv6_ph));
+       memcpy(dat + sizeof(struct ipv6_ph), data, nbytes);
+       return in_cksum(dat, sizeof(dat));
+}
+
 /* Fletcher Checksum -- Refer to RFC1008. */
 #define MODX                 4102U   /* 5802 should be fine */
 
@@ -53,13 +71,13 @@ int /* return checksum in low-order 16 bits */
    index required in the specification ISO 8473, Annex C.1 */
 /* calling with offset == FLETCHER_CHECKSUM_VALIDATE will validate the checksum
    without modifying the buffer; a valid checksum returns 0 */
-u_int16_t fletcher_checksum(u_char *buffer, const size_t len,
-                           const uint16_t offset)
+uint16_t fletcher_checksum(uint8_t *buffer, const size_t len,
+                          const uint16_t offset)
 {
-       u_int8_t *p;
+       uint8_t *p;
        int x, y, c0, c1;
-       u_int16_t checksum = 0;
-       u_int16_t *csum;
+       uint16_t checksum = 0;
+       uint16_t *csum;
        size_t partial_len, i, left = len;
 
        if (offset != FLETCHER_CHECKSUM_VALIDATE)
@@ -67,7 +85,7 @@ u_int16_t fletcher_checksum(u_char *buffer, const size_t len,
        {
                assert(offset
                       < (len - 1)); /* account for two bytes of checksum */
-               csum = (u_int16_t *)(buffer + offset);
+               csum = (uint16_t *)(buffer + offset);
                *(csum) = 0;
        }