Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.sbin/ldpd Constify a little bit
details: https://anonhg.NetBSD.org/src/rev/d5b8451031ce
branches: trunk
changeset: 787879:d5b8451031ce
user: kefren <kefren%NetBSD.org@localhost>
date: Thu Jul 11 05:45:23 2013 +0000
description:
Constify a little bit
diffstat:
usr.sbin/ldpd/fsm.c | 29 ++++++++++------------
usr.sbin/ldpd/fsm.h | 6 ++--
usr.sbin/ldpd/label.c | 4 +-
usr.sbin/ldpd/label.h | 6 ++--
usr.sbin/ldpd/ldp_peer.c | 54 ++++++++++++++++++++++++-----------------
usr.sbin/ldpd/ldp_peer.h | 31 ++++++++++++-----------
usr.sbin/ldpd/mpls_interface.c | 8 +++---
usr.sbin/ldpd/mpls_interface.h | 8 +++---
usr.sbin/ldpd/notifications.c | 4 +-
usr.sbin/ldpd/notifications.h | 6 ++--
usr.sbin/ldpd/pdu.c | 9 +++---
usr.sbin/ldpd/pdu.h | 6 ++--
usr.sbin/ldpd/socketops.c | 25 ++++++++++---------
usr.sbin/ldpd/socketops.h | 13 +++++----
usr.sbin/ldpd/tlv_stack.c | 17 +++++++------
usr.sbin/ldpd/tlv_stack.h | 11 ++++---
16 files changed, 123 insertions(+), 114 deletions(-)
diffs (truncated from 742 to 300 lines):
diff -r 7a585b86cffb -r d5b8451031ce usr.sbin/ldpd/fsm.c
--- a/usr.sbin/ldpd/fsm.c Wed Jul 10 23:30:45 2013 +0000
+++ b/usr.sbin/ldpd/fsm.c Thu Jul 11 05:45:23 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: fsm.c,v 1.10 2013/02/05 13:02:33 kefren Exp $ */
+/* $NetBSD: fsm.c,v 1.11 2013/07/11 05:45:23 kefren Exp $ */
/*-
* Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -49,13 +49,14 @@
char my_ldp_id[20];
struct sockaddr mplssockaddr;
-/* Processing a hello */
+/* Process a hello */
void
-run_ldp_hello(struct ldp_pdu * pduid, struct hello_tlv * ht,
- struct sockaddr * padd, struct in_addr * ladd, int mysock, bool may_connect)
+run_ldp_hello(const struct ldp_pdu * pduid, const struct hello_tlv * ht,
+ const struct sockaddr * padd, const struct in_addr * ladd, int mysock,
+ bool may_connect)
{
struct ldp_peer *peer = NULL;
- struct transport_address_tlv *trtlv;
+ const struct transport_address_tlv *trtlv;
struct hello_info *hi = NULL;
union sockunion traddr;
@@ -68,19 +69,15 @@
if (ht->length <= 4) /* Common hello parameters */
return;
- ht->ch.type = ntohs(ht->ch.type);
- ht->ch.length = ntohs(ht->ch.length);
- ht->ch.holdtime = ntohs(ht->ch.holdtime);
- ht->ch.res = ntohs(ht->ch.res);
- debugp("Common hello Type: 0x%.4X Length: %.2d R:%d T:%d"
- " Hold time: %d\n", ht->ch.type, ht->ch.length,
- ht->ch.tr / 2, ht->ch.tr % 2, ht->ch.holdtime);
+ debugp("Common hello Type: 0x%.4X Length: %.2d"
+ " Hold time: %d\n", ntohs(ht->ch.type), ntohs(ht->ch.length),
+ ht->ch.holdtime);
memset(&traddr, 0, sizeof(traddr));
/* Check transport TLV */
if (pduid->length - PDU_PAYLOAD_LENGTH -
sizeof(struct hello_tlv) >= 8) {
- trtlv = (struct transport_address_tlv *)(ht + 1);
+ trtlv = (const struct transport_address_tlv *)(ht + 1);
if (trtlv->type == htons(TLV_IPV4_TRANSPORT)) {
traddr.sin.sin_family = AF_INET;
traddr.sin.sin_len = sizeof(struct sockaddr_in);
@@ -119,9 +116,9 @@
/* Update expire timer */
if (ht->ch.holdtime != 0)
- hi->keepalive = ht->ch.holdtime;
+ hi->keepalive = ntohs(ht->ch.holdtime);
else {
- if (ht->ch.res >> 15 == 0)
+ if (ntohs(ht->ch.res) >> 15 == 0)
hi->keepalive = LDP_HELLO_KEEP;
else
hi->keepalive = LDP_THELLO_KEEP;
@@ -138,7 +135,7 @@
ntohl(ladd->s_addr))) {
peer = ldp_peer_new(&pduid->ldp_id, padd,
&hi->transport_address.sa,
- ht->ch.holdtime, 0);
+ ntohs(ht->ch.holdtime), 0);
if (peer == NULL)
return;
if (peer->state == LDP_PEER_CONNECTED)
diff -r 7a585b86cffb -r d5b8451031ce usr.sbin/ldpd/fsm.h
--- a/usr.sbin/ldpd/fsm.h Wed Jul 10 23:30:45 2013 +0000
+++ b/usr.sbin/ldpd/fsm.h Thu Jul 11 05:45:23 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: fsm.h,v 1.3 2013/02/03 19:41:59 kefren Exp $ */
+/* $NetBSD: fsm.h,v 1.4 2013/07/11 05:45:23 kefren Exp $ */
/*-
* Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -35,8 +35,8 @@
#include "tlv.h"
#include "pdu.h"
-void run_ldp_hello(struct ldp_pdu *, struct hello_tlv *,
- struct sockaddr *, struct in_addr *, int, bool);
+void run_ldp_hello(const struct ldp_pdu *, const struct hello_tlv *,
+ const struct sockaddr *, const struct in_addr *, int, bool);
struct address_list_tlv * build_address_list_tlv(void);
int set_my_ldp_id(void);
diff -r 7a585b86cffb -r d5b8451031ce usr.sbin/ldpd/label.c
--- a/usr.sbin/ldpd/label.c Wed Jul 10 23:30:45 2013 +0000
+++ b/usr.sbin/ldpd/label.c Thu Jul 11 05:45:23 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: label.c,v 1.4 2013/01/26 17:29:55 kefren Exp $ */
+/* $NetBSD: label.c,v 1.5 2013/07/11 05:45:23 kefren Exp $ */
/*-
* Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -175,7 +175,7 @@
* and reattach them to IPv4
*/
void
-label_reattach_all_peer_labels(struct ldp_peer *p, int readd)
+label_reattach_all_peer_labels(const struct ldp_peer *p, int readd)
{
struct label *l;
diff -r 7a585b86cffb -r d5b8451031ce usr.sbin/ldpd/label.h
--- a/usr.sbin/ldpd/label.h Wed Jul 10 23:30:45 2013 +0000
+++ b/usr.sbin/ldpd/label.h Thu Jul 11 05:45:23 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: label.h,v 1.2 2013/01/26 17:29:55 kefren Exp $ */
+/* $NetBSD: label.h,v 1.3 2013/07/11 05:45:23 kefren Exp $ */
/*-
* Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -51,7 +51,7 @@
struct label {
union sockunion so_dest, so_pref, so_gate;
int binding, label;
- struct ldp_peer *p;
+ const struct ldp_peer *p;
SLIST_ENTRY(label) labels;
};
SLIST_HEAD(,label) label_head;
@@ -61,7 +61,7 @@
union sockunion *, uint32_t, struct ldp_peer *, uint32_t);
void label_del(struct label *);
void del_all_peer_labels(struct ldp_peer*, int);
-void label_reattach_all_peer_labels(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_by_prefix(const struct sockaddr *, int);
diff -r 7a585b86cffb -r d5b8451031ce usr.sbin/ldpd/ldp_peer.c
--- a/usr.sbin/ldpd/ldp_peer.c Wed Jul 10 23:30:45 2013 +0000
+++ b/usr.sbin/ldpd/ldp_peer.c Thu Jul 11 05:45:23 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ldp_peer.c,v 1.11 2013/02/04 20:28:24 kefren Exp $ */
+/* $NetBSD: ldp_peer.c,v 1.12 2013/07/11 05:45:23 kefren Exp $ */
/*
* Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -76,8 +76,8 @@
* initiate a new one
*/
struct ldp_peer *
-ldp_peer_new(const struct in_addr * ldp_id, struct sockaddr * padd,
- struct sockaddr * tradd, uint16_t holdtime, int soc)
+ldp_peer_new(const struct in_addr * ldp_id, const struct sockaddr * padd,
+ const struct sockaddr * tradd, uint16_t holdtime, int soc)
{
struct ldp_peer *p;
int s = soc;
@@ -93,10 +93,13 @@
fatalp("ldp_peer_new: cannot create socket\n");
return NULL;
}
- if (tradd != NULL)
- connecting_sa = tradd;
- else
- connecting_sa = padd;
+ if (tradd != NULL) {
+ connecting_sa = malloc(tradd->sa_len);
+ memcpy(connecting_sa, tradd, tradd->sa_len);
+ } else {
+ connecting_sa = malloc(padd->sa_len);
+ memcpy(connecting_sa, padd, padd->sa_len);
+ }
assert(connecting_sa->sa_family == AF_INET ||
connecting_sa->sa_family == AF_INET6);
@@ -159,11 +162,13 @@
if (soc < 1)
if (connect(s, connecting_sa, connecting_sa->sa_len) == -1) {
if (errno == EINTR) {
+ free(connecting_sa);
return p; /* We take care of this in
* big_loop */
}
warnp("connect to %s failed: %s\n",
satos(connecting_sa), strerror(errno));
+ free(connecting_sa);
ldp_peer_holddown(p);
return NULL;
}
@@ -263,10 +268,10 @@
* Returns the number of addresses inserted successfuly
*/
int
-add_ifaddresses(struct ldp_peer * p, struct al_tlv * a)
+add_ifaddresses(struct ldp_peer * p, const struct al_tlv * a)
{
int i, c, n;
- struct in_addr *ia;
+ const struct in_addr *ia;
struct sockaddr_in ipa;
memset(&ipa, 0, sizeof(ipa));
@@ -288,7 +293,7 @@
debugp("Trying to add %d addresses to peer %s ... \n", n,
inet_ntoa(p->ldp_id));
- for (ia = (struct in_addr *) & a->address, c = 0, i = 0; i < n; i++) {
+ for (ia = (const struct in_addr *) & a->address,c = 0,i = 0; i<n; i++) {
memcpy(&ipa.sin_addr, &ia[i], sizeof(ipa.sin_addr));
if (add_ifaddr(p, (struct sockaddr *)&ipa) == LDP_E_OK)
c++;
@@ -300,10 +305,10 @@
}
int
-del_ifaddresses(struct ldp_peer * p, struct al_tlv * a)
+del_ifaddresses(struct ldp_peer * p, const struct al_tlv * a)
{
int i, c, n;
- struct in_addr *ia;
+ const struct in_addr *ia;
struct sockaddr_in ipa;
memset(&ipa, 0, sizeof(ipa));
@@ -324,7 +329,7 @@
debugp("Trying to delete %d addresses from peer %s ... \n", n,
inet_ntoa(p->ldp_id));
- for (ia = (struct in_addr *) & a[1], c = 0, i = 0; i < n; i++) {
+ for (ia = (const struct in_addr *) & a[1], c = 0, i = 0; i < n; i++) {
memcpy(&ipa.sin_addr, &ia[i], sizeof(ipa.sin_addr));
if (del_ifaddr(p, (struct sockaddr *)&ipa) == LDP_E_OK)
c++;
@@ -338,7 +343,7 @@
/* Adds a _SINGLE_ INET address to a specific peer */
int
-add_ifaddr(struct ldp_peer * p, struct sockaddr * a)
+add_ifaddr(struct ldp_peer * p, const struct sockaddr * a)
{
struct ldp_peer_address *lpa;
@@ -363,7 +368,7 @@
/* Deletes an address bounded to a specific peer */
int
-del_ifaddr(struct ldp_peer * p, struct sockaddr * a)
+del_ifaddr(struct ldp_peer * p, const struct sockaddr * a)
{
struct ldp_peer_address *wp;
@@ -379,7 +384,7 @@
/* Checks if an address is already bounded */
struct ldp_peer_address *
-check_ifaddr(struct ldp_peer * p, const struct sockaddr * a)
+check_ifaddr(const struct ldp_peer * p, const struct sockaddr * a)
{
struct ldp_peer_address *wp;
@@ -402,7 +407,7 @@
}
void
-print_bounded_addresses(struct ldp_peer * p)
+print_bounded_addresses(const struct ldp_peer * p)
{
struct ldp_peer_address *wp;
char abuf[512];
@@ -432,8 +437,8 @@
/* Adds a label and a prefix to a specific peer */
int
-ldp_peer_add_mapping(struct ldp_peer * p, struct sockaddr * a, int prefix,
- int label)
+ldp_peer_add_mapping(struct ldp_peer * p, const struct sockaddr * a,
+ int prefix, int label)
{
struct label_mapping *lma;
@@ -459,7 +464,8 @@
}
int
-ldp_peer_delete_mapping(struct ldp_peer * p, struct sockaddr * a, int prefix)
+ldp_peer_delete_mapping(struct ldp_peer * p, const struct sockaddr * a,
+ int prefix)
{
struct label_mapping *lma;
@@ -477,7 +483,8 @@
}
struct label_mapping *
-ldp_peer_get_lm(struct ldp_peer * p, struct sockaddr * a, uint prefix)
+ldp_peer_get_lm(const struct ldp_peer * p, const struct sockaddr * a,
+ uint prefix)
{
struct label_mapping *rv;
Home |
Main Index |
Thread Index |
Old Index