diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/frr_pthread.c | 30 | ||||
| -rw-r--r-- | lib/frr_pthread.h | 9 | ||||
| -rw-r--r-- | lib/mlag.c | 41 | ||||
| -rw-r--r-- | lib/mlag.h | 32 | ||||
| -rw-r--r-- | lib/subdir.am | 2 | ||||
| -rw-r--r-- | lib/thread.c | 7 | ||||
| -rw-r--r-- | lib/zclient.c | 1 | ||||
| -rw-r--r-- | lib/zclient.h | 3 |
8 files changed, 95 insertions, 30 deletions
diff --git a/lib/frr_pthread.c b/lib/frr_pthread.c index a0223730b8..d5a2007c4d 100644 --- a/lib/frr_pthread.c +++ b/lib/frr_pthread.c @@ -84,6 +84,8 @@ struct frr_pthread *frr_pthread_new(struct frr_pthread_attr *attr, fpt->name = XSTRDUP(MTYPE_FRR_PTHREAD, name); if (os_name) snprintf(fpt->os_name, OS_THREAD_NAMELEN, "%s", os_name); + else + snprintf(fpt->os_name, OS_THREAD_NAMELEN, "%s", name); /* initialize startup synchronization primitives */ fpt->running_cond_mtx = XCALLOC( MTYPE_PTHREAD_PRIM, sizeof(pthread_mutex_t)); @@ -115,36 +117,19 @@ void frr_pthread_destroy(struct frr_pthread *fpt) XFREE(MTYPE_FRR_PTHREAD, fpt); } -int frr_pthread_set_name(struct frr_pthread *fpt, const char *name, - const char *os_name) +int frr_pthread_set_name(struct frr_pthread *fpt) { int ret = 0; - if (name) { - pthread_mutex_lock(&fpt->mtx); - { - if (fpt->name) - XFREE(MTYPE_FRR_PTHREAD, fpt->name); - fpt->name = XSTRDUP(MTYPE_FRR_PTHREAD, name); - } - pthread_mutex_unlock(&fpt->mtx); - thread_master_set_name(fpt->master, name); - } - - if (os_name) { - pthread_mutex_lock(&fpt->mtx); - snprintf(fpt->os_name, OS_THREAD_NAMELEN, "%s", os_name); - pthread_mutex_unlock(&fpt->mtx); #ifdef HAVE_PTHREAD_SETNAME_NP # ifdef GNU_LINUX - ret = pthread_setname_np(fpt->thread, fpt->os_name); + ret = pthread_setname_np(fpt->thread, fpt->os_name); # else /* NetBSD */ - ret = pthread_setname_np(fpt->thread, fpt->os_name, NULL); + ret = pthread_setname_np(fpt->thread, fpt->os_name, NULL); # endif #elif defined(HAVE_PTHREAD_SET_NAME_NP) - pthread_set_name_np(fpt->thread, fpt->os_name); + pthread_set_name_np(fpt->thread, fpt->os_name); #endif - } return ret; } @@ -273,8 +258,7 @@ static void *fpt_run(void *arg) fpt->master->handle_signals = false; - if (fpt->os_name[0]) - frr_pthread_set_name(fpt, NULL, fpt->os_name); + frr_pthread_set_name(fpt); frr_pthread_notify_running(fpt); diff --git a/lib/frr_pthread.h b/lib/frr_pthread.h index b9e60511d5..e6b3f031b3 100644 --- a/lib/frr_pthread.h +++ b/lib/frr_pthread.h @@ -133,16 +133,13 @@ struct frr_pthread *frr_pthread_new(struct frr_pthread_attr *attr, const char *name, const char *os_name); /* - * Changes the name of the frr_pthread. + * Changes the name of the frr_pthread as reported by the operating + * system. * * @param fpt - the frr_pthread to operate on - * @param name - Human-readable name - * @param os_name - 16 characters thread name , including the null - * terminator ('\0') to set in os. * @return - on success returns 0 otherwise nonzero error number. */ -int frr_pthread_set_name(struct frr_pthread *fpt, const char *name, - const char *os_name); +int frr_pthread_set_name(struct frr_pthread *fpt); /* * Destroys an frr_pthread. diff --git a/lib/mlag.c b/lib/mlag.c new file mode 100644 index 0000000000..acdc662924 --- /dev/null +++ b/lib/mlag.c @@ -0,0 +1,41 @@ +/* mlag generic code. + * Copyright (C) 2018 Cumulus Networks, Inc. + * Donald Sharp + * + * This file is part of FRR. + * + * FRR is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2, or (at your option) any + * later version. + * + * FRR is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with FRR; see the file COPYING. If not, write to the Free + * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + */ +#include <zebra.h> + +#include <mlag.h> + +char *mlag_role2str(enum mlag_role role, char *buf, size_t size) +{ + switch (role) { + case MLAG_ROLE_NONE: + snprintf(buf, size, "NONE"); + break; + case MLAG_ROLE_PRIMARY: + snprintf(buf, size, "PRIMARY"); + break; + case MLAG_ROLE_SECONDARY: + snprintf(buf, size, "SECONDARY"); + break; + } + + return buf; +} diff --git a/lib/mlag.h b/lib/mlag.h new file mode 100644 index 0000000000..73725ca3fd --- /dev/null +++ b/lib/mlag.h @@ -0,0 +1,32 @@ +/* mlag header. + * Copyright (C) 2018 Cumulus Networks, Inc. + * Donald Sharp + * + * This file is part of FRR. + * + * FRR is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2, or (at your option) any + * later version. + * + * FRR is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with FRR; see the file COPYING. If not, write to the Free + * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + */ +#ifndef __MLAG_H__ +#define __MLAG_H__ + +enum mlag_role { + MLAG_ROLE_NONE, + MLAG_ROLE_PRIMARY, + MLAG_ROLE_SECONDARY +}; + +extern char *mlag_role2str(enum mlag_role role, char *buf, size_t size); +#endif diff --git a/lib/subdir.am b/lib/subdir.am index 43b39100cb..ccbe13bca6 100644 --- a/lib/subdir.am +++ b/lib/subdir.am @@ -44,6 +44,7 @@ lib_libfrr_la_SOURCES = \ lib/md5.c \ lib/memory.c \ lib/memory_vty.c \ + lib/mlag.c \ lib/module.c \ lib/mpls.c \ lib/network.c \ @@ -134,6 +135,7 @@ pkginclude_HEADERS += \ lib/bitfield.h \ lib/buffer.h \ lib/checksum.h \ + lib/mlag.h \ lib/command.h \ lib/command_graph.h \ lib/command_match.h \ diff --git a/lib/thread.c b/lib/thread.c index 44c9e2b2f1..867ca2dc60 100644 --- a/lib/thread.c +++ b/lib/thread.c @@ -1572,8 +1572,13 @@ void thread_set_yield_time(struct thread *thread, unsigned long yield_time) void thread_getrusage(RUSAGE_T *r) { +#if defined RUSAGE_THREAD +#define FRR_RUSAGE RUSAGE_THREAD +#else +#define FRR_RUSAGE RUSAGE_SELF +#endif monotime(&r->real); - getrusage(RUSAGE_SELF, &(r->cpu)); + getrusage(FRR_RUSAGE, &(r->cpu)); } /* diff --git a/lib/zclient.c b/lib/zclient.c index d2a6c75548..1c40750db0 100644 --- a/lib/zclient.c +++ b/lib/zclient.c @@ -2355,6 +2355,7 @@ static void zclient_capability_decode(int command, struct zclient *zclient, STREAM_GETC(s, mpls_enabled); cap.mpls_enabled = !!mpls_enabled; STREAM_GETL(s, cap.ecmp); + STREAM_GETC(s, cap.role); if (zclient->zebra_capabilities) (*zclient->zebra_capabilities)(&cap); diff --git a/lib/zclient.h b/lib/zclient.h index 8fe711f310..831cccfb7e 100644 --- a/lib/zclient.h +++ b/lib/zclient.h @@ -36,6 +36,8 @@ /* For union pw_protocol_fields */ #include "pw.h" +#include "mlag.h" + /* For input/output buffer to zebra. */ #define ZEBRA_MAX_PACKET_SIZ 16384 @@ -171,6 +173,7 @@ struct redist_proto { struct zclient_capabilities { uint32_t ecmp; bool mpls_enabled; + enum mlag_role role; }; /* Structure for the zebra client. */ |
