MFp4 bz_ipv6_fast:
in_cksum.h required ip.h to be included for struct ip. To be able to use some general checksum functions like in_addword() in a non-IPv4 context, limit the (also exported to user space) IPv4 specific functions to the times, when the ip.h header is present and IPVERSION is defined (to 4). We should consider more general checksum (updating) functions to also allow easier incremental checksum updates in the L3/4 stack and firewalls, as well as ponder further requirements by certain NIC drivers needing slightly different pseudo values in offloading cases. Thinking in terms of a better "library". Sponsored by: The FreeBSD Foundation Sponsored by: iXsystems Reviewed by: gnn (as part of the whole) MFC After: 3 days
This commit is contained in:
parent
8bed40c9fe
commit
920b965865
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=235941
@ -43,6 +43,7 @@
|
|||||||
|
|
||||||
#define in_cksum(m, len) in_cksum_skip(m, len, 0)
|
#define in_cksum(m, len) in_cksum_skip(m, len, 0)
|
||||||
|
|
||||||
|
#if defined(IPVERSION) && (IPVERSION == 4)
|
||||||
/*
|
/*
|
||||||
* It it useful to have an Internet checksum routine which is inlineable
|
* It it useful to have an Internet checksum routine which is inlineable
|
||||||
* and optimized specifically for the task of computing IP header checksums
|
* and optimized specifically for the task of computing IP header checksums
|
||||||
@ -69,9 +70,12 @@ in_cksum_update(struct ip *ip)
|
|||||||
} while(0)
|
} while(0)
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef _KERNEL
|
#ifdef _KERNEL
|
||||||
|
#if defined(IPVERSION) && (IPVERSION == 4)
|
||||||
u_int in_cksum_hdr(const struct ip *ip);
|
u_int in_cksum_hdr(const struct ip *ip);
|
||||||
|
#endif
|
||||||
u_short in_addword(u_short sum, u_short b);
|
u_short in_addword(u_short sum, u_short b);
|
||||||
u_short in_pseudo(u_int sum, u_int b, u_int c);
|
u_short in_pseudo(u_int sum, u_int b, u_int c);
|
||||||
u_short in_cksum_skip(struct mbuf *m, int len, int skip);
|
u_short in_cksum_skip(struct mbuf *m, int len, int skip);
|
||||||
|
@ -46,7 +46,9 @@ u_short in_cksum(struct mbuf *m, int len);
|
|||||||
u_short in_addword(u_short sum, u_short b);
|
u_short in_addword(u_short sum, u_short b);
|
||||||
u_short in_cksum_skip(struct mbuf *m, int len, int skip);
|
u_short in_cksum_skip(struct mbuf *m, int len, int skip);
|
||||||
u_int do_cksum(const void *, int);
|
u_int do_cksum(const void *, int);
|
||||||
|
#if defined(IPVERSION) && (IPVERSION == 4)
|
||||||
u_int in_cksum_hdr(const struct ip *);
|
u_int in_cksum_hdr(const struct ip *);
|
||||||
|
#endif
|
||||||
|
|
||||||
static __inline u_short
|
static __inline u_short
|
||||||
in_pseudo(u_int sum, u_int b, u_int c)
|
in_pseudo(u_int sum, u_int b, u_int c)
|
||||||
|
@ -54,6 +54,7 @@
|
|||||||
* therefore always exactly five 32-bit words.
|
* therefore always exactly five 32-bit words.
|
||||||
*/
|
*/
|
||||||
#if defined(__GNUCLIKE_ASM) && !defined(__INTEL_COMPILER)
|
#if defined(__GNUCLIKE_ASM) && !defined(__INTEL_COMPILER)
|
||||||
|
#if defined(IPVERSION) && (IPVERSION == 4)
|
||||||
static __inline u_int
|
static __inline u_int
|
||||||
in_cksum_hdr(const struct ip *ip)
|
in_cksum_hdr(const struct ip *ip)
|
||||||
{
|
{
|
||||||
@ -88,6 +89,7 @@ in_cksum_update(struct ip *ip)
|
|||||||
__tmpsum = (int)ntohs(ip->ip_sum) + 256;
|
__tmpsum = (int)ntohs(ip->ip_sum) + 256;
|
||||||
ip->ip_sum = htons(__tmpsum + (__tmpsum >> 16));
|
ip->ip_sum = htons(__tmpsum + (__tmpsum >> 16));
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static __inline u_short
|
static __inline u_short
|
||||||
in_addword(u_short sum, u_short b)
|
in_addword(u_short sum, u_short b)
|
||||||
@ -121,6 +123,7 @@ in_pseudo(u_int sum, u_int b, u_int c)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
#if defined(IPVERSION) && (IPVERSION == 4)
|
||||||
#define in_cksum_update(ip) \
|
#define in_cksum_update(ip) \
|
||||||
do { \
|
do { \
|
||||||
int __tmpsum; \
|
int __tmpsum; \
|
||||||
@ -129,10 +132,13 @@ in_pseudo(u_int sum, u_int b, u_int c)
|
|||||||
} while(0)
|
} while(0)
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef _KERNEL
|
#ifdef _KERNEL
|
||||||
#if !defined(__GNUCLIKE_ASM) || defined(__INTEL_COMPILER)
|
#if !defined(__GNUCLIKE_ASM) || defined(__INTEL_COMPILER)
|
||||||
|
#if defined(IPVERSION) && (IPVERSION == 4)
|
||||||
u_int in_cksum_hdr(const struct ip *ip);
|
u_int in_cksum_hdr(const struct ip *ip);
|
||||||
|
#endif
|
||||||
u_short in_addword(u_short sum, u_short b);
|
u_short in_addword(u_short sum, u_short b);
|
||||||
u_short in_pseudo(u_int sum, u_int b, u_int c);
|
u_short in_pseudo(u_int sum, u_int b, u_int c);
|
||||||
#endif
|
#endif
|
||||||
|
@ -39,6 +39,7 @@
|
|||||||
|
|
||||||
#define in_cksum(m, len) in_cksum_skip(m, len, 0)
|
#define in_cksum(m, len) in_cksum_skip(m, len, 0)
|
||||||
|
|
||||||
|
#if defined(IPVERSION) && (IPVERSION == 4)
|
||||||
/*
|
/*
|
||||||
* It it useful to have an Internet checksum routine which is inlineable
|
* It it useful to have an Internet checksum routine which is inlineable
|
||||||
* and optimized specifically for the task of computing IP header checksums
|
* and optimized specifically for the task of computing IP header checksums
|
||||||
@ -65,9 +66,12 @@ in_cksum_update(struct ip *ip)
|
|||||||
} while(0)
|
} while(0)
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef _KERNEL
|
#ifdef _KERNEL
|
||||||
|
#if defined(IPVERSION) && (IPVERSION == 4)
|
||||||
u_int in_cksum_hdr(const struct ip *ip);
|
u_int in_cksum_hdr(const struct ip *ip);
|
||||||
|
#endif
|
||||||
u_short in_addword(u_short sum, u_short b);
|
u_short in_addword(u_short sum, u_short b);
|
||||||
u_short in_pseudo(u_int sum, u_int b, u_int c);
|
u_short in_pseudo(u_int sum, u_int b, u_int c);
|
||||||
u_short in_cksum_skip(struct mbuf *m, int len, int skip);
|
u_short in_cksum_skip(struct mbuf *m, int len, int skip);
|
||||||
|
@ -40,6 +40,7 @@
|
|||||||
|
|
||||||
#define in_cksum(m, len) in_cksum_skip(m, len, 0)
|
#define in_cksum(m, len) in_cksum_skip(m, len, 0)
|
||||||
|
|
||||||
|
#if defined(IPVERSION) && (IPVERSION == 4)
|
||||||
/*
|
/*
|
||||||
* It it useful to have an Internet checksum routine which is inlineable
|
* It it useful to have an Internet checksum routine which is inlineable
|
||||||
* and optimized specifically for the task of computing IP header checksums
|
* and optimized specifically for the task of computing IP header checksums
|
||||||
@ -66,9 +67,12 @@ in_cksum_update(struct ip *ip)
|
|||||||
} while(0)
|
} while(0)
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef _KERNEL
|
#ifdef _KERNEL
|
||||||
|
#if defined(IPVERSION) && (IPVERSION == 4)
|
||||||
u_int in_cksum_hdr(const struct ip *ip);
|
u_int in_cksum_hdr(const struct ip *ip);
|
||||||
|
#endif
|
||||||
u_short in_addword(u_short sum, u_short b);
|
u_short in_addword(u_short sum, u_short b);
|
||||||
u_short in_pseudo(u_int sum, u_int b, u_int c);
|
u_short in_pseudo(u_int sum, u_int b, u_int c);
|
||||||
u_short in_cksum_skip(struct mbuf *m, int len, int skip);
|
u_short in_cksum_skip(struct mbuf *m, int len, int skip);
|
||||||
|
@ -39,6 +39,7 @@
|
|||||||
|
|
||||||
#define in_cksum(m, len) in_cksum_skip(m, len, 0)
|
#define in_cksum(m, len) in_cksum_skip(m, len, 0)
|
||||||
|
|
||||||
|
#if defined(IPVERSION) && (IPVERSION == 4)
|
||||||
/*
|
/*
|
||||||
* It it useful to have an Internet checksum routine which is inlineable
|
* It it useful to have an Internet checksum routine which is inlineable
|
||||||
* and optimized specifically for the task of computing IP header checksums
|
* and optimized specifically for the task of computing IP header checksums
|
||||||
@ -65,9 +66,12 @@ in_cksum_update(struct ip *ip)
|
|||||||
} while(0)
|
} while(0)
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef _KERNEL
|
#ifdef _KERNEL
|
||||||
|
#if defined(IPVERSION) && (IPVERSION == 4)
|
||||||
u_int in_cksum_hdr(const struct ip *ip);
|
u_int in_cksum_hdr(const struct ip *ip);
|
||||||
|
#endif
|
||||||
u_short in_addword(u_short sum, u_short b);
|
u_short in_addword(u_short sum, u_short b);
|
||||||
u_short in_pseudo(u_int sum, u_int b, u_int c);
|
u_short in_pseudo(u_int sum, u_int b, u_int c);
|
||||||
u_short in_cksum_skip(struct mbuf *m, int len, int skip);
|
u_short in_cksum_skip(struct mbuf *m, int len, int skip);
|
||||||
|
@ -65,6 +65,7 @@
|
|||||||
|
|
||||||
#define in_cksum(m, len) in_cksum_skip(m, len, 0)
|
#define in_cksum(m, len) in_cksum_skip(m, len, 0)
|
||||||
|
|
||||||
|
#if defined(IPVERSION) && (IPVERSION == 4)
|
||||||
static __inline void
|
static __inline void
|
||||||
in_cksum_update(struct ip *ip)
|
in_cksum_update(struct ip *ip)
|
||||||
{
|
{
|
||||||
@ -73,6 +74,7 @@ in_cksum_update(struct ip *ip)
|
|||||||
__tmp = (int)ip->ip_sum + 1;
|
__tmp = (int)ip->ip_sum + 1;
|
||||||
ip->ip_sum = __tmp + (__tmp >> 16);
|
ip->ip_sum = __tmp + (__tmp >> 16);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static __inline u_short
|
static __inline u_short
|
||||||
in_addword(u_short sum, u_short b)
|
in_addword(u_short sum, u_short b)
|
||||||
@ -106,6 +108,7 @@ in_pseudo(u_int sum, u_int b, u_int c)
|
|||||||
return (sum);
|
return (sum);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(IPVERSION) && (IPVERSION == 4)
|
||||||
static __inline u_int
|
static __inline u_int
|
||||||
in_cksum_hdr(struct ip *ip)
|
in_cksum_hdr(struct ip *ip)
|
||||||
{
|
{
|
||||||
@ -163,6 +166,7 @@ in_cksum_hdr(struct ip *ip)
|
|||||||
#undef __LD_ADD
|
#undef __LD_ADD
|
||||||
return (__ret);
|
return (__ret);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef _KERNEL
|
#ifdef _KERNEL
|
||||||
u_short in_cksum_skip(struct mbuf *m, int len, int skip);
|
u_short in_cksum_skip(struct mbuf *m, int len, int skip);
|
||||||
|
Loading…
Reference in New Issue
Block a user