0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2024-12-22 17:51:53 +00:00

Use IPv6 checksums in OSPFv3.

This commit is contained in:
Ondrej Zajicek 2009-11-09 23:22:53 +01:00
parent 3f22fa9e74
commit 4ac7c8341c
4 changed files with 28 additions and 2 deletions

View File

@ -60,6 +60,10 @@ int sk_setup_multicast(sock *s);
int sk_join_group(sock *s, ip_addr maddr); int sk_join_group(sock *s, ip_addr maddr);
int sk_leave_group(sock *s, ip_addr maddr); int sk_leave_group(sock *s, ip_addr maddr);
#ifdef IPV6
int sk_set_ipv6_checksum(sock *s, int offset);
#endif
static inline int static inline int
sk_send_buffer_empty(sock *sk) sk_send_buffer_empty(sock *sk)
{ {

View File

@ -89,6 +89,12 @@ ospf_open_socket(struct ospf_iface *ifa, int mc)
if (sk_open(ipsk) != 0) if (sk_open(ipsk) != 0)
goto err; goto err;
#ifdef OSPFv3
/* 12 is an offset of the checksum in an OSPF packet */
if (sk_set_ipv6_checksum(ipsk, 12) < 0)
goto err;
#endif
if (mc) if (mc)
{ {
if (sk_setup_multicast(ipsk) < 0) if (sk_setup_multicast(ipsk) < 0)

View File

@ -320,7 +320,6 @@ ospf_rx_hook(sock * sk, int size)
return 1; return 1;
} }
/* FIXME - handle checksums in OSPFv3 */
#ifdef OSPFv2 #ifdef OSPFv2
if ((ps->autype != htons(OSPF_AUTH_CRYPT)) && if ((ps->autype != htons(OSPF_AUTH_CRYPT)) &&
(!ipsum_verify(ps, 16, (void *) ps + sizeof(struct ospf_packet), (!ipsum_verify(ps, 16, (void *) ps + sizeof(struct ospf_packet),

View File

@ -782,12 +782,29 @@ int
sk_set_broadcast(sock *s, int enable) sk_set_broadcast(sock *s, int enable)
{ {
if (setsockopt(s->fd, SOL_SOCKET, SO_BROADCAST, &enable, sizeof(enable)) < 0) if (setsockopt(s->fd, SOL_SOCKET, SO_BROADCAST, &enable, sizeof(enable)) < 0)
{
log(L_ERR "sk_set_broadcast: SO_BROADCAST: %m"); log(L_ERR "sk_set_broadcast: SO_BROADCAST: %m");
return -1;
}
return 0;
} }
#ifdef IPV6 #ifdef IPV6
int
sk_set_ipv6_checksum(sock *s, int offset)
{
if (setsockopt(s->fd, IPPROTO_IPV6, IPV6_CHECKSUM, &offset, sizeof(offset)) < 0)
{
log(L_ERR "sk_set_ipv6_checksum: IPV6_CHECKSUM: %m");
return -1;
}
return 0;
}
int int
sk_setup_multicast(sock *s) sk_setup_multicast(sock *s)
{ {