]> git.proxmox.com Git - mirror_frr.git/blobdiff - isisd/isis_pfpacket.c
lib: enforce vrf_name_to_id by returning default_vrf when name is null
[mirror_frr.git] / isisd / isis_pfpacket.c
index 974d2b78cf4f7d34219c11a101c72564b12d19d9..2f6526bc5efa551ac4fa6fa80b079db0716dc293 100644 (file)
@@ -31,6 +31,7 @@
 #include "network.h"
 #include "stream.h"
 #include "if.h"
+#include "lib_errors.h"
 
 #include "isisd/dict.h"
 #include "isisd/isis_constants.h"
 #include "privs.h"
 
 /* tcpdump -i eth0 'isis' -dd */
-static struct sock_filter isisfilter[] =
-       {
-               /* NB: we're in SOCK_DGRAM, so src/dst mac + length are stripped
-                * off!
-                * (OTOH it's a bit more lower-layer agnostic and might work
-                * over GRE?) */
-               /*      { 0x28, 0, 0, 0x0000000c - 14 }, */
-               /*      { 0x25, 5, 0, 0x000005dc }, */
-               {0x28, 0, 0, 0x0000000e - 14}, {0x15, 0, 3, 0x0000fefe},
-               {0x30, 0, 0, 0x00000011 - 14}, {0x15, 0, 1, 0x00000083},
-               {0x6, 0, 0, 0x00040000},       {0x6, 0, 0, 0x00000000},
+static struct sock_filter isisfilter[] = {
+       /* NB: we're in SOCK_DGRAM, so src/dst mac + length are stripped
+        * off!
+        * (OTOH it's a bit more lower-layer agnostic and might work
+        * over GRE?) */
+       /*      { 0x28, 0, 0, 0x0000000c - 14 }, */
+       /*      { 0x25, 5, 0, 0x000005dc }, */
+       {0x28, 0, 0, 0x0000000e - 14}, {0x15, 0, 3, 0x0000fefe},
+       {0x30, 0, 0, 0x00000011 - 14}, {0x15, 0, 1, 0x00000083},
+       {0x6, 0, 0, 0x00040000},       {0x6, 0, 0, 0x00000000},
 };
 
 static struct sock_fprog bpf = {
@@ -68,10 +68,10 @@ static struct sock_fprog bpf = {
  * ISO 10589 - 8.4.8
  */
 
-u_char ALL_L1_ISS[6] = {0x01, 0x80, 0xC2, 0x00, 0x00, 0x14};
-u_char ALL_L2_ISS[6] = {0x01, 0x80, 0xC2, 0x00, 0x00, 0x15};
-u_char ALL_ISS[6] = {0x09, 0x00, 0x2B, 0x00, 0x00, 0x05};
-u_char ALL_ESS[6] = {0x09, 0x00, 0x2B, 0x00, 0x00, 0x04};
+uint8_t ALL_L1_ISS[6] = {0x01, 0x80, 0xC2, 0x00, 0x00, 0x14};
+uint8_t ALL_L2_ISS[6] = {0x01, 0x80, 0xC2, 0x00, 0x00, 0x15};
+uint8_t ALL_ISS[6] = {0x09, 0x00, 0x2B, 0x00, 0x00, 0x05};
+uint8_t ALL_ESS[6] = {0x09, 0x00, 0x2B, 0x00, 0x00, 0x04};
 
 static uint8_t discard_buff[8192];
 static uint8_t sock_buff[8192];
@@ -185,39 +185,34 @@ int isis_sock_init(struct isis_circuit *circuit)
 {
        int retval = ISIS_OK;
 
-       if (isisd_privs.change(ZPRIVS_RAISE))
-               zlog_err("%s: could not raise privs, %s", __func__,
-                        safe_strerror(errno));
+       frr_elevate_privs(&isisd_privs) {
 
-       retval = open_packet_socket(circuit);
+               retval = open_packet_socket(circuit);
 
-       if (retval != ISIS_OK) {
-               zlog_warn("%s: could not initialize the socket", __func__);
-               goto end;
-       }
+               if (retval != ISIS_OK) {
+                       zlog_warn("%s: could not initialize the socket",
+                                 __func__);
+                       break;
+               }
 
        /* Assign Rx and Tx callbacks are based on real if type */
-       if (if_is_broadcast(circuit->interface)) {
-               circuit->tx = isis_send_pdu_bcast;
-               circuit->rx = isis_recv_pdu_bcast;
-       } else if (if_is_pointopoint(circuit->interface)) {
-               circuit->tx = isis_send_pdu_p2p;
-               circuit->rx = isis_recv_pdu_p2p;
-       } else {
-               zlog_warn("isis_sock_init(): unknown circuit type");
-               retval = ISIS_WARNING;
-               goto end;
+               if (if_is_broadcast(circuit->interface)) {
+                       circuit->tx = isis_send_pdu_bcast;
+                       circuit->rx = isis_recv_pdu_bcast;
+               } else if (if_is_pointopoint(circuit->interface)) {
+                       circuit->tx = isis_send_pdu_p2p;
+                       circuit->rx = isis_recv_pdu_p2p;
+               } else {
+                       zlog_warn("isis_sock_init(): unknown circuit type");
+                       retval = ISIS_WARNING;
+                       break;
+               }
        }
 
-end:
-       if (isisd_privs.change(ZPRIVS_LOWER))
-               zlog_err("%s: could not lower privs, %s", __func__,
-                        safe_strerror(errno));
-
        return retval;
 }
 
-static inline int llc_check(u_char *llc)
+static inline int llc_check(uint8_t *llc)
 {
        if (*llc != ISO_SAP || *(llc + 1) != ISO_SAP || *(llc + 2) != 3)
                return 0;
@@ -225,11 +220,11 @@ static inline int llc_check(u_char *llc)
        return 1;
 }
 
-int isis_recv_pdu_bcast(struct isis_circuit *circuit, u_char *ssnpa)
+int isis_recv_pdu_bcast(struct isis_circuit *circuit, uint8_t *ssnpa)
 {
        int bytesread, addr_len;
        struct sockaddr_ll s_addr;
-       u_char llc[LLC_LEN];
+       uint8_t llc[LLC_LEN];
 
        addr_len = sizeof(s_addr);
 
@@ -301,7 +296,7 @@ int isis_recv_pdu_bcast(struct isis_circuit *circuit, u_char *ssnpa)
        return ISIS_OK;
 }
 
-int isis_recv_pdu_p2p(struct isis_circuit *circuit, u_char *ssnpa)
+int isis_recv_pdu_p2p(struct isis_circuit *circuit, uint8_t *ssnpa)
 {
        int bytesread, addr_len;
        struct sockaddr_ll s_addr;
@@ -310,9 +305,9 @@ int isis_recv_pdu_p2p(struct isis_circuit *circuit, u_char *ssnpa)
        addr_len = sizeof(s_addr);
 
        /* we can read directly to the stream */
-       stream_recvfrom(circuit->rcv_stream, circuit->fd,
-                       circuit->interface->mtu, 0, (struct sockaddr *)&s_addr,
-                       (socklen_t *)&addr_len);
+       (void)stream_recvfrom(
+               circuit->rcv_stream, circuit->fd, circuit->interface->mtu, 0,
+               (struct sockaddr *)&s_addr, (socklen_t *)&addr_len);
 
        if (s_addr.sll_pkttype == PACKET_OUTGOING) {
                /*  Read the packet into discard buff */