Quagga bgp_accept code

314 views Asked by At

I am trying to understand what the following (code below) is doing, and am struggling to understand the concept of sockunions. Can anyone help me out? What has this got to do with threads and thread file descriptors?

Appreciate your help in advance, and would be open to any resources you can recommmend!

Sarah


static int
bgp_accept (struct thread *thread)
{
int bgp_sock;
int accept_sock;
union sockunion su;
struct bgp_listener *listener = THREAD_ARG(thread);
struct peer *peer;
struct peer *peer1;
char buf[SU_ADDRSTRLEN];

/* Register accept thread. */
accept_sock = THREAD_FD (thread);

    if (accept_sock < 0)
    {
    zlog_err ("accept_sock is nevative value %d", accept_sock);
    return -1;
    }

listener->thread = thread_add_read (master, bgp_accept, listener, accept_sock);

/* Accept client connection. */
bgp_sock = sockunion_accept (accept_sock, &su);
    if (bgp_sock < 0)
    {
...
1

There are 1 answers

0
Arjun Prasad On

bgp_accept is a self calling (thread_add_read) function.(read quagga thread concept don't confused with linux thread concept). Every call of bgp_accept it will establish a tcp connection with other peers.