Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/ldpd sprinkle more const



details:   https://anonhg.NetBSD.org/src/rev/5ff6a6393e22
branches:  trunk
changeset: 787890:5ff6a6393e22
user:      kefren <kefren%NetBSD.org@localhost>
date:      Thu Jul 11 10:46:19 2013 +0000

description:
sprinkle more const

diffstat:

 usr.sbin/ldpd/conffile.c    |   4 +-
 usr.sbin/ldpd/conffile.h    |   4 +-
 usr.sbin/ldpd/label.c       |  12 +++---
 usr.sbin/ldpd/label.h       |  11 +++---
 usr.sbin/ldpd/mpls_routes.c |  72 +++++++++++++++++++++++++++++++-------------
 usr.sbin/ldpd/mpls_routes.h |  13 ++++---
 usr.sbin/ldpd/tlv_stack.c   |  26 ++++++++-------
 usr.sbin/ldpd/tlv_stack.h   |  19 ++++++-----
 8 files changed, 97 insertions(+), 64 deletions(-)

diffs (truncated from 424 to 300 lines):

diff -r 6e38829040e2 -r 5ff6a6393e22 usr.sbin/ldpd/conffile.c
--- a/usr.sbin/ldpd/conffile.c  Thu Jul 11 09:11:35 2013 +0000
+++ b/usr.sbin/ldpd/conffile.c  Thu Jul 11 10:46:19 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: conffile.c,v 1.5 2013/01/26 21:07:49 kefren Exp $ */
+/* $NetBSD: conffile.c,v 1.6 2013/07/11 10:46:19 kefren Exp $ */
 
 /*
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -90,7 +90,7 @@
  * Parses config file
  */
 int
-conf_parsefile(char *fname)
+conf_parsefile(const char *fname)
 {
        int i;
        char buf[LINEMAXSIZE + 1];
diff -r 6e38829040e2 -r 5ff6a6393e22 usr.sbin/ldpd/conffile.h
--- a/usr.sbin/ldpd/conffile.h  Thu Jul 11 09:11:35 2013 +0000
+++ b/usr.sbin/ldpd/conffile.h  Thu Jul 11 10:46:19 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: conffile.h,v 1.2 2013/01/26 21:07:49 kefren Exp $ */
+/* $NetBSD: conffile.h,v 1.3 2013/07/11 10:46:19 kefren Exp $ */
 
 /*
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -57,6 +57,6 @@
 };
 SLIST_HEAD(,passive_if) passifs_head;
 
-int conf_parsefile(char *fname);
+int conf_parsefile(const char *fname);
 
 #endif
diff -r 6e38829040e2 -r 5ff6a6393e22 usr.sbin/ldpd/label.c
--- a/usr.sbin/ldpd/label.c     Thu Jul 11 09:11:35 2013 +0000
+++ b/usr.sbin/ldpd/label.c     Thu Jul 11 10:46:19 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: label.c,v 1.5 2013/07/11 05:45:23 kefren Exp $ */
+/* $NetBSD: label.c,v 1.6 2013/07/11 10:46:19 kefren Exp $ */
 
 /*-
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -53,9 +53,9 @@
  * if binding == 0 it receives a free one
  */
 struct label   *
-label_add(union sockunion * so_dest, union sockunion * so_pref,
-         union sockunion * so_gate, uint32_t binding, struct ldp_peer * p,
-         uint32_t label)
+label_add(const union sockunion * so_dest, const union sockunion * so_pref,
+         const union sockunion * so_gate, uint32_t binding,
+         const struct ldp_peer * p, uint32_t label)
 {
        struct label   *l;
        char    spreftmp[INET_ADDRSTRLEN];
@@ -157,7 +157,7 @@
  * Get a label by dst and pref
  */
 struct label*
-label_get(union sockunion *sodest, union sockunion *sopref)
+label_get(const union sockunion *sodest, const union sockunion *sopref)
 {
        struct label *l;
 
@@ -189,7 +189,7 @@
  * and delete them
  */
 void 
-del_all_peer_labels(struct ldp_peer * p, int readd)
+del_all_peer_labels(const struct ldp_peer * p, int readd)
 {
        struct label   *l, *lnext;
 
diff -r 6e38829040e2 -r 5ff6a6393e22 usr.sbin/ldpd/label.h
--- a/usr.sbin/ldpd/label.h     Thu Jul 11 09:11:35 2013 +0000
+++ b/usr.sbin/ldpd/label.h     Thu Jul 11 10:46:19 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: label.h,v 1.3 2013/07/11 05:45:23 kefren Exp $ */
+/* $NetBSD: label.h,v 1.4 2013/07/11 10:46:19 kefren Exp $ */
 
 /*-
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -57,13 +57,14 @@
 SLIST_HEAD(,label) label_head;
 
 void            label_init(void);
-struct label * label_add(union sockunion *, union sockunion *,
-         union sockunion *, uint32_t, struct ldp_peer *, uint32_t);
+struct label * label_add(const union sockunion *, const union sockunion *,
+         const union sockunion *, uint32_t, const struct ldp_peer *, uint32_t);
 void            label_del(struct label *);
-void            del_all_peer_labels(struct ldp_peer*, int);
+void            del_all_peer_labels(const struct ldp_peer*, int);
 void           label_reattach_all_peer_labels(const struct ldp_peer*, int);
 void            label_del_by_binding(uint32_t, int);
-struct label * label_get(union sockunion *sodest, union sockunion *sopref);
+struct label * label_get(const union sockunion *sodest,
+       const union sockunion *sopref);
 struct label * label_get_by_prefix(const struct sockaddr *, int);
 uint32_t       get_free_local_label(void);
 void           change_local_label(struct label*, uint32_t);
diff -r 6e38829040e2 -r 5ff6a6393e22 usr.sbin/ldpd/mpls_routes.c
--- a/usr.sbin/ldpd/mpls_routes.c       Thu Jul 11 09:11:35 2013 +0000
+++ b/usr.sbin/ldpd/mpls_routes.c       Thu Jul 11 10:46:19 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: mpls_routes.c,v 1.11 2013/07/11 09:11:35 kefren Exp $ */
+/* $NetBSD: mpls_routes.c,v 1.12 2013/07/11 10:46:19 kefren Exp $ */
 
 /*-
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -66,7 +66,7 @@
 
 static int read_route_socket(char *, int);
 void   mask_addr(union sockunion *);
-int    compare_sockunion(union sockunion *, union sockunion *);
+int    compare_sockunion(const union sockunion *, const union sockunion *);
 char * mpls_ntoa(union mpls_shim);
 
 extern struct sockaddr mplssockaddr;
@@ -196,8 +196,8 @@
 }
 
 int
-compare_sockunion(union sockunion * __restrict a,
-    union sockunion * __restrict b)
+compare_sockunion(const union sockunion * __restrict a,
+    const union sockunion * __restrict b)
 {
        if (a->sa.sa_len != b->sa.sa_len)
                return 1;
@@ -227,7 +227,7 @@
 }
 
 uint8_t 
-from_mask_to_cidr(char *mask)
+from_mask_to_cidr(const char *mask)
 {
        struct in_addr addr;
        uint8_t plen = 0;
@@ -239,9 +239,9 @@
 }
 
 uint8_t
-from_union_to_cidr(union sockunion *so_pref)
+from_union_to_cidr(const union sockunion *so_pref)
 {
-       struct sockaddr_in *sin = (struct sockaddr_in*)so_pref;
+       const struct sockaddr_in *sin = (const struct sockaddr_in*) so_pref;
        uint32_t a;
        uint8_t r;
 
@@ -265,7 +265,7 @@
 }
 
 char *
-mpls_ntoa(union mpls_shim ms)
+mpls_ntoa(const union mpls_shim ms)
 {
        static char     ret[255];
        union mpls_shim ms2;
@@ -275,10 +275,11 @@
        return ret;
 }
 
-char           *
-union_ntoa(union sockunion * so)
+char *
+union_ntoa(const union sockunion * so)
 {
-       static char     defret[] = "Unknown family address";
+       static char defret[] = "Unknown family address";
+
        switch (so->sa.sa_family) {
        case AF_INET:
                return inet_ntoa(so->sin.sin_addr);
@@ -313,8 +314,8 @@
 /* Adds a route. Or changes it. */
 int
 add_route(union sockunion *so_dest, union sockunion *so_prefix,
-    union sockunion *so_gate, union sockunion *so_ifa, union sockunion *so_tag,
-    int fr, int optype)
+    union sockunion *so_gate, union sockunion *so_ifa,
+    union sockunion *so_tag, int fr, int optype)
 {
        int             l, rlen, rv = LDP_E_OK;
        struct rt_msg   rm;
@@ -343,8 +344,19 @@
                NEXTADDR(so_gate);
 
        if (so_prefix) {
-               mask_addr(so_prefix);
-               NEXTADDR(so_prefix);
+               union sockunion *so_prefix_temp = so_prefix;
+
+               if (fr != FREESO) {
+                       /* don't modify so_prefix */
+                       so_prefix_temp = calloc(1, so_prefix->sa.sa_len);
+                       if (so_prefix_temp == NULL)
+                               return LDP_E_MEMORY;
+                       memcpy(so_prefix_temp, so_prefix, so_prefix->sa.sa_len);
+               }
+               mask_addr(so_prefix_temp);
+               NEXTADDR(so_prefix_temp);
+               if (fr != FREESO)
+                       free(so_prefix_temp);
                /* XXX: looks like nobody cares about this */
                rm.m_rtm.rtm_flags |= RTF_MASK;
                rm.m_rtm.rtm_addrs |= RTA_NETMASK;
@@ -378,7 +390,7 @@
                        warnp("Gateway was: %s\n", union_ntoa(so_gate));
                rv = LDP_E_ROUTE_ERROR;
        }
-       if (fr) {
+       if (fr == FREESO) {
                free(so_dest);
                if (so_prefix)
                        free(so_prefix);
@@ -420,8 +432,18 @@
        NEXTADDR(so_dest);
 
        if (so_pref) {
-               mask_addr(so_pref);
-               NEXTADDR(so_pref);
+               union sockunion *so_pref_temp = so_pref; 
+               if (freeso != FREESO) {
+                       /* don't modify the original prefix */
+                       so_pref_temp = calloc(1, so_pref->sa.sa_len);
+                       if (so_pref_temp == NULL)
+                               return LDP_E_MEMORY;
+                       memcpy(so_pref_temp, so_pref, so_pref->sa.sa_len);
+               }
+               mask_addr(so_pref_temp);
+               NEXTADDR(so_pref_temp);
+               if (freeso != FREESO)
+                       free(so_pref_temp);
        }
        rm.m_rtm.rtm_msglen = l = cp - (char *) &rm;
 
@@ -452,8 +474,8 @@
  * with the returned result
  */
 int
-get_route(struct rt_msg * rg, union sockunion * so_dest,
-    union sockunion * so_pref, int exact_match)
+get_route(struct rt_msg * rg, const union sockunion * so_dest,
+    const union sockunion * so_pref, int exact_match)
 {
        int             l, rlen, myseq;
        struct rt_msg   rm;
@@ -484,9 +506,15 @@
 
        NEXTADDR(so_dest);
        if (so_pref) {
+               union sockunion *so_pref_temp = calloc(1, so_pref->sa.sa_len);
+
+               if (so_pref_temp == NULL)
+                       return LDP_E_MEMORY;
                rm.m_rtm.rtm_addrs |= RTA_NETMASK;
-               mask_addr(so_pref);
-               NEXTADDR(so_pref);
+               memcpy(so_pref_temp, so_pref, so_pref->sa.sa_len);
+               mask_addr(so_pref_temp);
+               NEXTADDR(so_pref_temp);
+               free(so_pref_temp);
        }
        rm.m_rtm.rtm_msglen = l = cp - (char *) &rm;
 
diff -r 6e38829040e2 -r 5ff6a6393e22 usr.sbin/ldpd/mpls_routes.h
--- a/usr.sbin/ldpd/mpls_routes.h       Thu Jul 11 09:11:35 2013 +0000
+++ b/usr.sbin/ldpd/mpls_routes.h       Thu Jul 11 10:46:19 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: mpls_routes.h,v 1.3 2013/01/26 17:29:55 kefren Exp $ */
+/* $NetBSD: mpls_routes.h,v 1.4 2013/07/11 10:46:19 kefren Exp $ */
 
 /*-
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -63,17 +63,18 @@
 union sockunion *      make_mpls_union(uint32_t);
 union sockunion        *       make_mplsinet_union(uint16_t peer, uint32_t label,
                                                struct in_addr *addr);
-uint8_t        from_mask_to_cidr(char *);
+uint8_t        from_mask_to_cidr(const char *);
 void   from_cidr_to_mask(uint8_t, char *);
 int    add_route(union sockunion *, union sockunion *, union sockunion *,
-                       union sockunion *, union sockunion *, int, int);
+               union sockunion *, union sockunion *, int, int);
 int    delete_route(union sockunion *, union sockunion *, int);
-int    get_route(struct rt_msg *, union sockunion *, union sockunion *, int);
+int    get_route(struct rt_msg *, const union sockunion *,
+               const union sockunion *, int);
 int    bind_current_routes(void);
 int    flush_mpls_routes(void);
 int    check_route(struct rt_msg *, uint);
-char*  union_ntoa(union sockunion *);
-uint8_t        from_union_to_cidr(union sockunion *);
+char*  union_ntoa(const union sockunion *);
+uint8_t        from_union_to_cidr(const union sockunion *);
 union sockunion *      from_cidr_to_union(uint8_t);



Home | Main Index | Thread Index | Old Index