23 #include <freeradius-devel/util/net.h>
29 {
L(
"ICMP"), IPPROTO_ICMP },
30 {
L(
"ICMPv6"), IPPROTO_ICMPV6 },
31 {
L(
"TCP"), IPPROTO_TCP },
32 {
L(
"UDP"), IPPROTO_UDP }
40 {
L(
"TCP"), SOCK_STREAM },
41 {
L(
"UDP"), SOCK_DGRAM }
49 {
L(
"IPv4"), AF_INET },
50 {
L(
"IPv6"), AF_INET6 }
77 udp_len = ntohs(udp->
len);
78 actual_len = remaining;
80 if (udp_len > actual_len) {
81 fr_strerror_printf(
"packet too small by %zi bytes, UDP header + Payload should be %hu bytes",
82 (udp_len - actual_len), udp_len);
86 else if (udp_len < actual_len) {
87 fr_strerror_printf(
"Packet too big by %zi bytes, UDP header + Payload should be %hu bytes",
88 (actual_len - udp_len), udp_len);
97 ntohs(udp->
checksum), ntohs(expected));
120 struct in_addr
const src_addr,
struct in_addr
const dst_addr)
125 uint16_t const *ip_src = (
void const *) &src_addr.s_addr;
126 uint16_t const *ip_dst = (
void const *) &dst_addr.s_addr;
134 sum += htons(IPPROTO_UDP);
137 for (i = len; i > 1; i -= 2) sum += *p++;
138 if (i) sum += (0xff & *(
uint8_t const *)p) << 8;
142 while (sum >> 16) sum = (sum & 0xffff) + (sum >> 16);
161 for (sum = 0; nwords > 0; nwords--) {
164 sum = (sum >> 16) + (sum & 0xffff);
174 int8_t nwords =
sizeof(ip6) >> 1;
176 memcpy(&ip6.ip_src, src,
sizeof(ip6.ip_src));
181 for (sum = 0; nwords > 0; nwords--) {
183 memcpy(&word, p,
sizeof(word));
187 sum = (sum >> 16) + (sum & 0xffff);
#define L(_str)
Helper for initialising arrays of string literals.
size_t fr_net_af_table_len
fr_table_num_sorted_t const fr_net_sock_type_table[]
Strings for socket types.
uint16_t fr_ip6_pesudo_header_checksum(struct in6_addr const *src, struct in6_addr const *dst, uint16_t ip_len, uint8_t ip_next)
fr_table_num_sorted_t const fr_net_ip_proto_table[]
Strings for L4 protocols.
int fr_udp_header_check(uint8_t const *data, uint16_t remaining, ip_header_t const *ip)
Check UDP header is valid.
uint16_t fr_udp_checksum(uint8_t const *data, uint16_t len, uint16_t checksum, struct in_addr const src_addr, struct in_addr const dst_addr)
Calculate UDP checksum.
size_t fr_net_ip_proto_table_len
fr_table_num_sorted_t const fr_net_af_table[]
Strings for address families.
uint16_t fr_ip_header_checksum(uint8_t const *data, uint8_t ihl)
Calculate IP header checksum.
size_t fr_net_sock_type_table_len
uint32_t ip_next
upper 24 bits must be zero
struct in6_addr ip_src ip_dst
Src and Dst address.
uint16_t checksum
UDP checksum.
struct in_addr ip_src ip_dst
Src and Dst address.
An element in a lexicographically sorted array of name to num mappings.
#define fr_strerror_printf(_fmt,...)
Log to thread local error buffer.