diff options
author | Everton Marques <everton.marques@gmail.com> | 2009-11-19 17:00:23 -0200 |
---|---|---|
committer | David Lamparter <equinox@opensourcerouting.org> | 2015-02-04 06:07:52 +0100 |
commit | 7c5f50125d9ef099336660330b7432fb848b7e75 (patch) | |
tree | f613d81b87bfdb74c759168731c43626e181f6b5 | |
parent | dba7758a7fa712fc712cd3063a2724bb15c92e60 (diff) | |
download | quagga-7c5f50125d9ef099336660330b7432fb848b7e75.tar.bz2 quagga-7c5f50125d9ef099336660330b7432fb848b7e75.tar.xz |
[pim] Fix net/host byte order
-rw-r--r-- | pimd/Makefile.am | 4 | ||||
-rw-r--r-- | pimd/pim_assert.c | 19 | ||||
-rw-r--r-- | pimd/pim_assert.h | 2 | ||||
-rw-r--r-- | pimd/pim_int.c | 44 | ||||
-rw-r--r-- | pimd/pim_int.h | 31 | ||||
-rw-r--r-- | pimd/pim_tlv.c | 23 | ||||
-rw-r--r-- | pimd/pim_tlv.h | 16 |
7 files changed, 108 insertions, 31 deletions
diff --git a/pimd/Makefile.am b/pimd/Makefile.am index 57bd31ae..4aae6378 100644 --- a/pimd/Makefile.am +++ b/pimd/Makefile.am @@ -53,7 +53,7 @@ libpim_a_SOURCES = \ pim_oil.c pim_zlookup.c pim_pim.c pim_tlv.c pim_neighbor.c \ pim_hello.c pim_ifchannel.c pim_join.c pim_assert.c \ pim_msg.c pim_upstream.c pim_rpf.c pim_rand.c pim_macro.c \ - pim_igmp_join.c pim_ssmpingd.c + pim_igmp_join.c pim_ssmpingd.c pim_int.c noinst_HEADERS = \ pimd.h pim_version.h pim_cmd.h pim_signals.h pim_iface.h \ @@ -62,7 +62,7 @@ noinst_HEADERS = \ pim_oil.h pim_zlookup.h pim_pim.h pim_tlv.h pim_neighbor.h \ pim_hello.h pim_ifchannel.h pim_join.h pim_assert.h \ pim_msg.h pim_upstream.h pim_rpf.h pim_rand.h pim_macro.h \ - pim_igmp_join.h pim_ssmpingd.h + pim_igmp_join.h pim_ssmpingd.h pim_int.h pimd_SOURCES = \ pim_main.c $(libpim_a_SOURCES) diff --git a/pimd/pim_assert.c b/pimd/pim_assert.c index 0ce0e5d0..52168d69 100644 --- a/pimd/pim_assert.c +++ b/pimd/pim_assert.c @@ -30,6 +30,7 @@ #include "pim_tlv.h" #include "pim_msg.h" #include "pim_pim.h" +#include "pim_int.h" #include "pim_time.h" #include "pim_iface.h" #include "pim_hello.h" @@ -297,7 +298,7 @@ int pim_assert_recv(struct interface *ifp, Parse assert metric preference */ - msg_metric.metric_preference = ntohl(*(const uint32_t *) curr); + msg_metric.metric_preference = pim_read_uint32_host(curr); msg_metric.rpt_bit_flag = msg_metric.metric_preference & 0x80000000; /* save highest bit */ msg_metric.metric_preference &= ~0x80000000; /* clear highest bit */ @@ -308,7 +309,7 @@ int pim_assert_recv(struct interface *ifp, Parse assert route metric */ - msg_metric.route_metric = ntohl(*(const uint32_t *) curr); + msg_metric.route_metric = pim_read_uint32_host(curr); if (PIM_DEBUG_PIM_TRACE) { char neigh_str[100]; @@ -378,7 +379,7 @@ int pim_assert_metric_match(const struct pim_assert_metric *m1, return m1->ip_address.s_addr == m2->ip_address.s_addr; } -int pim_assert_build_msg(char *pim_msg, int buf_size, +int pim_assert_build_msg(uint8_t *pim_msg, int buf_size, struct interface *ifp, struct in_addr group_addr, struct in_addr source_addr, @@ -386,8 +387,8 @@ int pim_assert_build_msg(char *pim_msg, int buf_size, uint32_t route_metric, uint32_t rpt_bit_flag) { - char *buf_pastend = pim_msg + buf_size; - char *pim_msg_curr; + uint8_t *buf_pastend = pim_msg + buf_size; + uint8_t *pim_msg_curr; int pim_msg_size; int remain; @@ -420,13 +421,13 @@ int pim_assert_build_msg(char *pim_msg, int buf_size, } /* Metric preference */ - *((uint32_t *) pim_msg_curr) = htonl(rpt_bit_flag ? - metric_preference | 0x80000000 : - metric_preference); + pim_write_uint32(pim_msg_curr, rpt_bit_flag ? + metric_preference | 0x80000000 : + metric_preference); pim_msg_curr += 4; /* Route metric */ - *((uint32_t *) pim_msg_curr) = htonl(route_metric); + pim_write_uint32(pim_msg_curr, route_metric); pim_msg_curr += 4; /* diff --git a/pimd/pim_assert.h b/pimd/pim_assert.h index 6a8594ce..feeb91df 100644 --- a/pimd/pim_assert.h +++ b/pimd/pim_assert.h @@ -58,7 +58,7 @@ int pim_assert_metric_better(const struct pim_assert_metric *m1, int pim_assert_metric_match(const struct pim_assert_metric *m1, const struct pim_assert_metric *m2); -int pim_assert_build_msg(char *pim_msg, int buf_size, +int pim_assert_build_msg(uint8_t *pim_msg, int buf_size, struct interface *ifp, struct in_addr group_addr, struct in_addr source_addr, diff --git a/pimd/pim_int.c b/pimd/pim_int.c new file mode 100644 index 00000000..2ff1a116 --- /dev/null +++ b/pimd/pim_int.c @@ -0,0 +1,44 @@ +/* + PIM for Quagga + Copyright (C) 2008 Everton da Silva Marques + + This program 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 of the License, or + (at your option) any later version. + + This program 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 this program; see the file COPYING; if not, write to the + Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, + MA 02110-1301 USA + + $QuaggaId: $Format:%an, %ai, %h$ $ +*/ + +#include <string.h> +#include <netinet/in.h> + +#include "pim_int.h" + +uint32_t pim_read_uint32_host(const uint8_t *buf) +{ + uint32_t val; + memcpy(&val, buf, sizeof(val)); + /* val is in netorder */ + val = ntohl(val); + /* val is in hostorder */ + return val; +} + +void pim_write_uint32(uint8_t *buf, uint32_t val_host) +{ + /* val_host is in host order */ + val_host = htonl(val_host); + /* val_host is in netorder */ + memcpy(buf, &val_host, sizeof(val_host)); +} diff --git a/pimd/pim_int.h b/pimd/pim_int.h new file mode 100644 index 00000000..d64b1032 --- /dev/null +++ b/pimd/pim_int.h @@ -0,0 +1,31 @@ +/* + PIM for Quagga + Copyright (C) 2008 Everton da Silva Marques + + This program 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 of the License, or + (at your option) any later version. + + This program 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 this program; see the file COPYING; if not, write to the + Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, + MA 02110-1301 USA + + $QuaggaId: $Format:%an, %ai, %h$ $ +*/ + +#ifndef PIM_INT_H +#define PIM_INT_H + +#include <stdint.h> + +uint32_t pim_read_uint32_host(const uint8_t *buf); +void pim_write_uint32(uint8_t *buf, uint32_t val_host); + +#endif /* PIM_INT_H */ diff --git a/pimd/pim_tlv.c b/pimd/pim_tlv.c index fc48c888..16b7e93e 100644 --- a/pimd/pim_tlv.c +++ b/pimd/pim_tlv.c @@ -26,12 +26,13 @@ #include "prefix.h" #include "pimd.h" +#include "pim_int.h" #include "pim_tlv.h" #include "pim_str.h" #include "pim_msg.h" -char *pim_tlv_append_uint16(char *buf, - const char *buf_pastend, +char *pim_tlv_append_uint16(uint8_t *buf, + const uint8_t *buf_pastend, uint16_t option_type, uint16_t option_value) { @@ -54,8 +55,8 @@ char *pim_tlv_append_uint16(char *buf, return buf; } -char *pim_tlv_append_2uint16(char *buf, - const char *buf_pastend, +char *pim_tlv_append_2uint16(uint8_t *buf, + const uint8_t *buf_pastend, uint16_t option_type, uint16_t option_value1, uint16_t option_value2) @@ -81,8 +82,8 @@ char *pim_tlv_append_2uint16(char *buf, return buf; } -char *pim_tlv_append_uint32(char *buf, - const char *buf_pastend, +char *pim_tlv_append_uint32(uint8_t *buf, + const uint8_t *buf_pastend, uint16_t option_type, uint32_t option_value) { @@ -99,7 +100,7 @@ char *pim_tlv_append_uint32(char *buf, buf += 2; *(uint16_t *) buf = htons(option_len); buf += 2; - *(uint32_t *) buf = htonl(option_value); + pim_write_uint32(buf, option_value); buf += option_len; return buf; @@ -107,14 +108,14 @@ char *pim_tlv_append_uint32(char *buf, #define ucast_ipv4_encoding_len (2 + sizeof(struct in_addr)) -char *pim_tlv_append_addrlist_ucast(char *buf, - const char *buf_pastend, +char *pim_tlv_append_addrlist_ucast(uint8_t *buf, + const uint8_t *buf_pastend, struct list *ifconnected) { struct listnode *node; uint16_t option_len = 0; - char *curr; + uint8_t *curr; node = listhead(ifconnected); @@ -323,7 +324,7 @@ int pim_tlv_parse_dr_priority(const char *ifname, struct in_addr src_addr, PIM_OPTION_SET(*hello_options, PIM_OPTION_MASK_DR_PRIORITY); *hello_option_dr_priority = PIM_TLV_GET_DR_PRIORITY(tlv_curr); - + return 0; } diff --git a/pimd/pim_tlv.h b/pimd/pim_tlv.h index 9602cb1c..5ec3dc43 100644 --- a/pimd/pim_tlv.h +++ b/pimd/pim_tlv.h @@ -71,21 +71,21 @@ typedef uint32_t pim_hello_options; #define PIM_TLV_MIN_SIZE (PIM_TLV_TYPE_SIZE + PIM_TLV_LENGTH_SIZE) #define PIM_TLV_OPTION_SIZE(option_len) (PIM_TLV_MIN_SIZE + (option_len)) -char *pim_tlv_append_uint16(char *buf, - const char *buf_pastend, +char *pim_tlv_append_uint16(uint8_t *buf, + const uint8_t *buf_pastend, uint16_t option_type, uint16_t option_value); -char *pim_tlv_append_2uint16(char *buf, - const char *buf_pastend, +char *pim_tlv_append_2uint16(uint8_t *buf, + const uint8_t *buf_pastend, uint16_t option_type, uint16_t option_value1, uint16_t option_value2); -char *pim_tlv_append_uint32(char *buf, - const char *buf_pastend, +char *pim_tlv_append_uint32(uint8_t *buf, + const uint8_t *buf_pastend, uint16_t option_type, uint32_t option_value); -char *pim_tlv_append_addrlist_ucast(char *buf, - const char *buf_pastend, +char *pim_tlv_append_addrlist_ucast(uint8_t *buf, + const uint8_t *buf_pastend, struct list *ifconnected); int pim_tlv_parse_holdtime(const char *ifname, struct in_addr src_addr, |