]> git.proxmox.com Git - mirror_frr.git/blobdiff - bgpd/bgp_io.c
zebra: Refactor kernel_rtm to be a bit smarter about how it handles options
[mirror_frr.git] / bgpd / bgp_io.c
index 69c92e829c59ce6174a792ee08df89470cd6e6b6..f111822e53ca5f46460b0147af65aa415ae848e3 100644 (file)
@@ -23,7 +23,7 @@
 #include <zebra.h>
 #include <pthread.h>           // for pthread_mutex_unlock, pthread_mutex_lock
 
-#include "frr_pthread.h"       // for frr_pthread_get, frr_pthread
+#include "frr_pthread.h"
 #include "linklist.h"          // for list_delete, list_delete_all_node, lis...
 #include "log.h"               // for zlog_debug, safe_strerror, zlog_err
 #include "memory.h"            // for MTYPE_TMP, XCALLOC, XFREE
@@ -35,6 +35,7 @@
 
 #include "bgpd/bgp_io.h"
 #include "bgpd/bgp_debug.h"    // for bgp_debug_neighbor_events, bgp_type_str
+#include "bgpd/bgp_errors.h"   // for expanded error reference information
 #include "bgpd/bgp_fsm.h"      // for BGP_EVENT_ADD, bgp_event
 #include "bgpd/bgp_packet.h"   // for bgp_notify_send_with_data, bgp_notify...
 #include "bgpd/bgpd.h"         // for peer, BGP_MARKER_SIZE, bgp_master, bm
@@ -55,7 +56,7 @@ static bool validate_header(struct peer *);
 
 void bgp_writes_on(struct peer *peer)
 {
-       struct frr_pthread *fpt = frr_pthread_get(PTHREAD_IO);
+       struct frr_pthread *fpt = bgp_pth_io;
        assert(fpt->running);
 
        assert(peer->status != Deleted);
@@ -73,7 +74,7 @@ void bgp_writes_on(struct peer *peer)
 
 void bgp_writes_off(struct peer *peer)
 {
-       struct frr_pthread *fpt = frr_pthread_get(PTHREAD_IO);
+       struct frr_pthread *fpt = bgp_pth_io;
        assert(fpt->running);
 
        thread_cancel_async(fpt->master, &peer->t_write, NULL);
@@ -84,7 +85,7 @@ void bgp_writes_off(struct peer *peer)
 
 void bgp_reads_on(struct peer *peer)
 {
-       struct frr_pthread *fpt = frr_pthread_get(PTHREAD_IO);
+       struct frr_pthread *fpt = bgp_pth_io;
        assert(fpt->running);
 
        assert(peer->status != Deleted);
@@ -104,7 +105,7 @@ void bgp_reads_on(struct peer *peer)
 
 void bgp_reads_off(struct peer *peer)
 {
-       struct frr_pthread *fpt = frr_pthread_get(PTHREAD_IO);
+       struct frr_pthread *fpt = bgp_pth_io;
        assert(fpt->running);
 
        thread_cancel_async(fpt->master, &peer->t_read, NULL);
@@ -129,7 +130,7 @@ static int bgp_process_writes(struct thread *thread)
        if (peer->fd < 0)
                return -1;
 
-       struct frr_pthread *fpt = frr_pthread_get(PTHREAD_IO);
+       struct frr_pthread *fpt = bgp_pth_io;
 
        pthread_mutex_lock(&peer->io_mtx);
        {
@@ -174,7 +175,6 @@ static int bgp_process_reads(struct thread *thread)
        bool more = true;               // whether we got more data
        bool fatal = false;             // whether fatal error occurred
        bool added_pkt = false;         // whether we pushed onto ->ibuf
-       bool header_valid = true;       // whether header is valid
        /* clang-format on */
 
        peer = THREAD_ARG(thread);
@@ -182,7 +182,7 @@ static int bgp_process_reads(struct thread *thread)
        if (peer->fd < 0 || bm->terminating)
                return -1;
 
-       struct frr_pthread *fpt = frr_pthread_get(PTHREAD_IO);
+       struct frr_pthread *fpt = bgp_pth_io;
 
        pthread_mutex_lock(&peer->io_mtx);
        {
@@ -214,10 +214,8 @@ static int bgp_process_reads(struct thread *thread)
                if (ringbuf_remain(ibw) < BGP_HEADER_SIZE)
                        break;
 
-               /* validate header */
-               header_valid = validate_header(peer);
-
-               if (!header_valid) {
+               /* check that header is valid */
+               if (!validate_header(peer)) {
                        fatal = true;
                        break;
                }
@@ -297,7 +295,7 @@ static uint16_t bgp_write(struct peer *peer)
                int writenum;
                do {
                        writenum = stream_get_endp(s) - stream_get_getp(s);
-                       num = write(peer->fd, STREAM_PNT(s), writenum);
+                       num = write(peer->fd, stream_pnt(s), writenum);
 
                        if (num < 0) {
                                if (!ERRNO_IO_RETRY(errno)) {
@@ -404,7 +402,8 @@ static uint16_t bgp_read(struct peer *peer)
                SET_FLAG(status, BGP_IO_TRANS_ERR);
                /* Fatal error; tear down session */
        } else if (nbytes < 0) {
-               zlog_err("%s [Error] bgp_read_packet error: %s", peer->host,
+               flog_err(EC_BGP_UPDATE_RCV,
+                        "%s [Error] bgp_read_packet error: %s", peer->host,
                         safe_strerror(errno));
 
                if (peer->status == Established) {