--- embedaddon/quagga/ospf6d/ospf6_network.c 2012/02/21 17:26:12 1.1 +++ embedaddon/quagga/ospf6d/ospf6_network.c 2016/11/02 10:09:11 1.1.1.3 @@ -27,6 +27,7 @@ #include "sockopt.h" #include "privs.h" +#include "libospf.h" #include "ospf6_proto.h" #include "ospf6_network.h" @@ -36,18 +37,8 @@ int ospf6_sock; struct in6_addr allspfrouters6; struct in6_addr alldrouters6; -/* setsockopt ReUseAddr to on */ -void -ospf6_set_reuseaddr (void) -{ - u_int on = 0; - if (setsockopt (ospf6_sock, SOL_SOCKET, SO_REUSEADDR, &on, - sizeof (u_int)) < 0) - zlog_warn ("Network: set SO_REUSEADDR failed: %s", safe_strerror (errno)); -} - /* setsockopt MulticastLoop to off */ -void +static void ospf6_reset_mcastloop (void) { u_int off = 0; @@ -57,13 +48,21 @@ ospf6_reset_mcastloop (void) safe_strerror (errno)); } -void +static void ospf6_set_pktinfo (void) { setsockopt_ipv6_pktinfo (ospf6_sock, 1); } -void +static void +ospf6_set_transport_class (void) +{ +#ifdef IPTOS_PREC_INTERNETCONTROL + setsockopt_ipv6_tclass (ospf6_sock, IPTOS_PREC_INTERNETCONTROL); +#endif +} + +static void ospf6_set_checksum (void) { int offset = 12; @@ -102,6 +101,7 @@ ospf6_serv_sock (void) #endif /*1*/ ospf6_reset_mcastloop (); ospf6_set_pktinfo (); + ospf6_set_transport_class (); ospf6_set_checksum (); /* setup global in6_addr, allspf6 and alldr6 for later use */ @@ -111,88 +111,24 @@ ospf6_serv_sock (void) return 0; } +/* ospf6 set socket option */ void -ospf6_join_allspfrouters (u_int ifindex) +ospf6_sso (ifindex_t ifindex, struct in6_addr *group, int option) { struct ipv6_mreq mreq6; - int retval; + int ret; assert (ifindex); mreq6.ipv6mr_interface = ifindex; - memcpy (&mreq6.ipv6mr_multiaddr, &allspfrouters6, - sizeof (struct in6_addr)); + memcpy (&mreq6.ipv6mr_multiaddr, group, sizeof (struct in6_addr)); - retval = setsockopt (ospf6_sock, IPPROTO_IPV6, IPV6_JOIN_GROUP, - &mreq6, sizeof (mreq6)); - - if (retval < 0) - zlog_err ("Network: Join AllSPFRouters on ifindex %d failed: %s", - ifindex, safe_strerror (errno)); -#if 0 - else - zlog_debug ("Network: Join AllSPFRouters on ifindex %d", ifindex); -#endif + ret = setsockopt (ospf6_sock, IPPROTO_IPV6, option, + &mreq6, sizeof (mreq6)); + if (ret < 0) + zlog_err ("Network: setsockopt (%d) on ifindex %d failed: %s", + option, ifindex, safe_strerror (errno)); } -void -ospf6_leave_allspfrouters (u_int ifindex) -{ - struct ipv6_mreq mreq6; - - assert (ifindex); - mreq6.ipv6mr_interface = ifindex; - memcpy (&mreq6.ipv6mr_multiaddr, &allspfrouters6, - sizeof (struct in6_addr)); - - if (setsockopt (ospf6_sock, IPPROTO_IPV6, IPV6_LEAVE_GROUP, - &mreq6, sizeof (mreq6)) < 0) - zlog_warn ("Network: Leave AllSPFRouters on ifindex %d Failed: %s", - ifindex, safe_strerror (errno)); -#if 0 - else - zlog_debug ("Network: Leave AllSPFRouters on ifindex %d", ifindex); -#endif -} - -void -ospf6_join_alldrouters (u_int ifindex) -{ - struct ipv6_mreq mreq6; - - assert (ifindex); - mreq6.ipv6mr_interface = ifindex; - memcpy (&mreq6.ipv6mr_multiaddr, &alldrouters6, - sizeof (struct in6_addr)); - - if (setsockopt (ospf6_sock, IPPROTO_IPV6, IPV6_JOIN_GROUP, - &mreq6, sizeof (mreq6)) < 0) - zlog_warn ("Network: Join AllDRouters on ifindex %d Failed: %s", - ifindex, safe_strerror (errno)); -#if 0 - else - zlog_debug ("Network: Join AllDRouters on ifindex %d", ifindex); -#endif -} - -void -ospf6_leave_alldrouters (u_int ifindex) -{ - struct ipv6_mreq mreq6; - - assert (ifindex); - mreq6.ipv6mr_interface = ifindex; - memcpy (&mreq6.ipv6mr_multiaddr, &alldrouters6, - sizeof (struct in6_addr)); - - if (setsockopt (ospf6_sock, IPPROTO_IPV6, IPV6_LEAVE_GROUP, - &mreq6, sizeof (mreq6)) < 0) - zlog_warn ("Network: Leave AllDRouters on ifindex %d Failed", ifindex); -#if 0 - else - zlog_debug ("Network: Leave AllDRouters on ifindex %d", ifindex); -#endif -} - static int iov_count (struct iovec *iov) { @@ -214,7 +150,7 @@ iov_totallen (struct iovec *iov) int ospf6_sendmsg (struct in6_addr *src, struct in6_addr *dst, - unsigned int *ifindex, struct iovec *message) + ifindex_t *ifindex, struct iovec *message) { int retval; struct msghdr smsghdr; @@ -260,7 +196,7 @@ ospf6_sendmsg (struct in6_addr *src, struct in6_addr * smsghdr.msg_name = (caddr_t) &dst_sin6; smsghdr.msg_namelen = sizeof (struct sockaddr_in6); smsghdr.msg_control = (caddr_t) cmsgbuf; - smsghdr.msg_controllen = sizeof (cmsgbuf); + smsghdr.msg_controllen = scmsgp->cmsg_len; retval = sendmsg (ospf6_sock, &smsghdr, 0); if (retval != iov_totallen (message)) @@ -272,7 +208,7 @@ ospf6_sendmsg (struct in6_addr *src, struct in6_addr * int ospf6_recvmsg (struct in6_addr *src, struct in6_addr *dst, - unsigned int *ifindex, struct iovec *message) + ifindex_t *ifindex, struct iovec *message) { int retval; struct msghdr rmsghdr;