Mailing List Archive

[PATCHv3 1/4] bgpd: eliminate RD related duplicate code in bgp_encap.c decode_rd_... apis are declared global in bgp_mplsvpn.c
---
bgpd/bgp_encap.c | 45 ---------------------------------------------
bgpd/bgp_mplsvpn.c | 8 ++++----
bgpd/bgp_mplsvpn.h | 5 +++++
3 files changed, 9 insertions(+), 49 deletions(-)

diff --git a/bgpd/bgp_encap.c b/bgpd/bgp_encap.c
index edd9d76..8361d3f 100644
--- a/bgpd/bgp_encap.c
+++ b/bgpd/bgp_encap.c
@@ -45,51 +45,6 @@ Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
#include "bgpd/bgp_vty.h"
#include "bgpd/bgp_encap.h"

-static u_int16_t
-decode_rd_type (u_char *pnt)
-{
- u_int16_t v;
-
- v = ((u_int16_t) *pnt++ << 8);
- v |= (u_int16_t) *pnt;
- return v;
-}
-
-
-static void
-decode_rd_as (u_char *pnt, struct rd_as *rd_as)
-{
- rd_as->as = (u_int16_t) *pnt++ << 8;
- rd_as->as |= (u_int16_t) *pnt++;
-
- rd_as->val = ((u_int32_t) *pnt++) << 24;
- rd_as->val |= ((u_int32_t) *pnt++) << 16;
- rd_as->val |= ((u_int32_t) *pnt++) << 8;
- rd_as->val |= (u_int32_t) *pnt;
-}
-
-static void
-decode_rd_as4 (u_char *pnt, struct rd_as *rd_as)
-{
- rd_as->as = (u_int32_t) *pnt++ << 24;
- rd_as->as |= (u_int32_t) *pnt++ << 16;
- rd_as->as |= (u_int32_t) *pnt++ << 8;
- rd_as->as |= (u_int32_t) *pnt++;
-
- rd_as->val = ((u_int32_t) *pnt++ << 8);
- rd_as->val |= (u_int32_t) *pnt;
-}
-
-static void
-decode_rd_ip (u_char *pnt, struct rd_ip *rd_ip)
-{
- memcpy (&rd_ip->ip, pnt, 4);
- pnt += 4;
-
- rd_ip->val = ((u_int16_t) *pnt++ << 8);
- rd_ip->val |= (u_int16_t) *pnt;
-}
-
static void
ecom2prd(struct ecommunity *ecom, struct prefix_rd *prd)
{
diff --git a/bgpd/bgp_mplsvpn.c b/bgpd/bgp_mplsvpn.c
index 047105d..392a239 100644
--- a/bgpd/bgp_mplsvpn.c
+++ b/bgpd/bgp_mplsvpn.c
@@ -35,7 +35,7 @@ Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
#include "bgpd/bgp_mplsvpn.h"
#include "bgpd/bgp_packet.h"

-static u_int16_t
+u_int16_t
decode_rd_type (u_char *pnt)
{
u_int16_t v;
@@ -57,7 +57,7 @@ decode_label (u_char *pnt)
}

/* type == RD_TYPE_AS */
-static void
+void
decode_rd_as (u_char *pnt, struct rd_as *rd_as)
{
rd_as->as = (u_int16_t) *pnt++ << 8;
@@ -70,7 +70,7 @@ decode_rd_as (u_char *pnt, struct rd_as *rd_as)
}

/* type == RD_TYPE_AS4 */
-static void
+void
decode_rd_as4 (u_char *pnt, struct rd_as *rd_as)
{
rd_as->as = (u_int32_t) *pnt++ << 24;
@@ -83,7 +83,7 @@ decode_rd_as4 (u_char *pnt, struct rd_as *rd_as)
}

/* type == RD_TYPE_IP */
-static void
+void
decode_rd_ip (u_char *pnt, struct rd_ip *rd_ip)
{
memcpy (&rd_ip->ip, pnt, 4);
diff --git a/bgpd/bgp_mplsvpn.h b/bgpd/bgp_mplsvpn.h
index 3299b9c..3fbbd33 100644
--- a/bgpd/bgp_mplsvpn.h
+++ b/bgpd/bgp_mplsvpn.h
@@ -41,9 +41,14 @@ struct rd_ip
u_int16_t val;
};

+extern u_int16_t decode_rd_type (u_char *);
extern void bgp_mplsvpn_init (void);
extern int bgp_nlri_parse_vpn (struct peer *, struct attr *, struct bgp_nlri *);
extern u_int32_t decode_label (u_char *);
+extern void encode_label(u_int32_t, u_char *);
+extern void decode_rd_as (u_char *, struct rd_as *);
+extern void decode_rd_as4 (u_char *, struct rd_as *);
+extern void decode_rd_ip (u_char *, struct rd_ip *);
extern int str2prefix_rd (const char *, struct prefix_rd *);
extern int str2tag (const char *, u_char *);
extern char *prefix_rd2str (struct prefix_rd *, char *, size_t);
--
2.1.3


_______________________________________________
Quagga-dev mailing list
Quagga-dev@lists.quagga.net
https://lists.quagga.net/mailman/listinfo/quagga-dev
Re: [PATCHv3 1/4] bgpd: eliminate RD related duplicate code in bgp_encap.c decode_rd_... apis are declared global in bgp_mplsvpn.c [ In reply to ]
On Mon, Oct 10, 2016 at 8:36 PM, Lou Berger <lberger@labn.net> wrote:

Hello Lou,

> ---
> bgpd/bgp_encap.c | 45 ---------------------------------------------
> bgpd/bgp_mplsvpn.c | 8 ++++----
> bgpd/bgp_mplsvpn.h | 5 +++++
> 3 files changed, 9 insertions(+), 49 deletions(-)
>
It is interesting to factorise, provided that it does not take off clarity.



Meanwhile, I am thinking of pushing a rework, to move RD utilities to
a dedicated lib file.

Best Regards,

Philippe

Acked-by: Philippe Guibert <philippe.guibert@6wind.com>

_______________________________________________
Quagga-dev mailing list
Quagga-dev@lists.quagga.net
https://lists.quagga.net/mailman/listinfo/quagga-dev