mirror of
https://gitlab.labs.nic.cz/labs/bird.git
synced 2024-05-11 16:54:54 +00:00
Implements TTL security for OSPF and RIP.
Interfaces for OSPF and RIP could be configured to use (and request) TTL 255 for traffic to direct neighbors. Thanks to Simon Dickhoven for the original patch for RIPng.
This commit is contained in:
@@ -194,17 +194,22 @@ sk_set_md5_auth_int(sock *s, sockaddr *sa, char *passwd)
|
||||
/* RX/TX packet info handling for IPv4 */
|
||||
/* Mostly similar to standardized IPv6 code */
|
||||
|
||||
#define CMSG_RX_SPACE CMSG_SPACE(sizeof(struct in_pktinfo))
|
||||
#define CMSG_RX_SPACE (CMSG_SPACE(sizeof(struct in_pktinfo)) + CMSG_SPACE(sizeof(int)))
|
||||
#define CMSG_TX_SPACE CMSG_SPACE(sizeof(struct in_pktinfo))
|
||||
|
||||
static char *
|
||||
sysio_register_cmsgs(sock *s)
|
||||
{
|
||||
int ok = 1;
|
||||
|
||||
if ((s->flags & SKF_LADDR_RX) &&
|
||||
setsockopt(s->fd, IPPROTO_IP, IP_PKTINFO, &ok, sizeof(ok)) < 0)
|
||||
(setsockopt(s->fd, IPPROTO_IP, IP_PKTINFO, &ok, sizeof(ok)) < 0))
|
||||
return "IP_PKTINFO";
|
||||
|
||||
if ((s->flags & SKF_TTL_RX) &&
|
||||
(setsockopt(s->fd, IPPROTO_IP, IP_RECVTTL, &ok, sizeof(ok)) < 0))
|
||||
return "IP_RECVTTL";
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -213,25 +218,34 @@ sysio_process_rx_cmsgs(sock *s, struct msghdr *msg)
|
||||
{
|
||||
struct cmsghdr *cm;
|
||||
struct in_pktinfo *pi = NULL;
|
||||
|
||||
if (!(s->flags & SKF_LADDR_RX))
|
||||
return;
|
||||
int *ttl = NULL;
|
||||
|
||||
for (cm = CMSG_FIRSTHDR(msg); cm != NULL; cm = CMSG_NXTHDR(msg, cm))
|
||||
{
|
||||
if (cm->cmsg_level == IPPROTO_IP && cm->cmsg_type == IP_PKTINFO)
|
||||
pi = (struct in_pktinfo *) CMSG_DATA(cm);
|
||||
}
|
||||
{
|
||||
if (cm->cmsg_level == IPPROTO_IP && cm->cmsg_type == IP_PKTINFO)
|
||||
pi = (struct in_pktinfo *) CMSG_DATA(cm);
|
||||
|
||||
if (!pi)
|
||||
if (cm->cmsg_level == IPPROTO_IP && cm->cmsg_type == IP_TTL)
|
||||
ttl = (int *) CMSG_DATA(cm);
|
||||
}
|
||||
|
||||
if (s->flags & SKF_LADDR_RX)
|
||||
{
|
||||
if (pi)
|
||||
{
|
||||
get_inaddr(&s->laddr, &pi->ipi_addr);
|
||||
s->lifindex = pi->ipi_ifindex;
|
||||
}
|
||||
else
|
||||
{
|
||||
s->laddr = IPA_NONE;
|
||||
s->lifindex = 0;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (s->flags & SKF_TTL_RX)
|
||||
s->ttl = ttl ? *ttl : -1;
|
||||
|
||||
get_inaddr(&s->laddr, &pi->ipi_addr);
|
||||
s->lifindex = pi->ipi_ifindex;
|
||||
return;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user