summaryrefslogtreecommitdiffstats
path: root/proto/ospf/lsalib.c
diff options
context:
space:
mode:
authorOndrej Zajicek <santiago@crfreenet.org>2009-09-08 17:06:47 +0200
committerOndrej Zajicek <santiago@crfreenet.org>2009-09-08 17:06:47 +0200
commitc15e569065e80f91b4c9c77b86640aac72aa0a47 (patch)
tree3642d78a327ded168c7cc5eb75c4b756b02bbb01 /proto/ospf/lsalib.c
parentbe862406627da3bd1facea9309b3f32e67422eab (diff)
downloadbird-c15e569065e80f91b4c9c77b86640aac72aa0a47.tar
bird-c15e569065e80f91b4c9c77b86640aac72aa0a47.zip
Make endianity swapping simpler.
Diffstat (limited to 'proto/ospf/lsalib.c')
-rw-r--r--proto/ospf/lsalib.c149
1 files changed, 14 insertions, 135 deletions
diff --git a/proto/ospf/lsalib.c b/proto/ospf/lsalib.c
index 31b5118..64e94a9 100644
--- a/proto/ospf/lsalib.c
+++ b/proto/ospf/lsalib.c
@@ -105,7 +105,7 @@ htonlsah(struct ospf_lsa_header *h, struct ospf_lsa_header *n)
n->sn = htonl(h->sn);
n->checksum = htons(h->checksum);
n->length = htons(h->length);
-};
+}
void
ntohlsah(struct ospf_lsa_header *n, struct ospf_lsa_header *h)
@@ -120,150 +120,29 @@ ntohlsah(struct ospf_lsa_header *n, struct ospf_lsa_header *h)
h->sn = ntohl(n->sn);
h->checksum = ntohs(n->checksum);
h->length = ntohs(n->length);
-};
+}
void
htonlsab(void *h, void *n, u16 type, u16 len)
{
- unsigned int i;
-
- switch (type)
- {
- case LSA_T_RT:
- {
- struct ospf_lsa_rt *hrt, *nrt;
- struct ospf_lsa_rt_link *hrtl, *nrtl;
- u16 links;
-
- nrt = n;
- hrt = h;
-
-#ifdef OSPFv2
- links = hrt->links;
- nrt->options = htons(hrt->options);
- nrt->links = htons(hrt->links);
-#else /* OSPFv3 */
- nrt->options = htonl(hrt->options);
- links = (len - sizeof(struct ospf_lsa_rt)) /
- sizeof(struct ospf_lsa_rt_link);
-#endif
-
- nrtl = (struct ospf_lsa_rt_link *) (nrt + 1);
- hrtl = (struct ospf_lsa_rt_link *) (hrt + 1);
- for (i = 0; i < links; i++)
- {
-#ifdef OSPFv2
- nrtl[i].id = htonl(hrtl[i].id);
- nrtl[i].data = htonl(hrtl[i].data);
- nrtl[i].type = hrtl[i].type;
- nrtl[i].notos = hrtl[i].notos;
- nrtl[i].metric = htons(hrtl[i].metric);
-#else /* OSPFv3 */
- nrtl[i].type = hrtl[i].type;
- nrtl[i].padding = 0;
- nrtl[i].metric = htons(hrtl[i].metric);
- nrtl[i].lif = htonl(hrtl[i].lif);
- nrtl[i].nif = htonl(hrtl[i].nif);
- nrtl[i].id = htonl(hrtl[i].id);
-#endif
- }
- break;
- }
- case LSA_T_NET:
- case LSA_T_SUM_NET:
- case LSA_T_SUM_RT:
- case LSA_T_EXT:
-#ifdef OSPFv3
- case LSA_T_LINK:
- case LSA_T_PREFIX:
-#endif
- {
- u32 *hid, *nid;
-
- nid = n;
- hid = h;
-
- for (i = 0; i < (len / sizeof(u32)); i++)
- {
- *(nid + i) = htonl(*(hid + i));
- }
- break;
- }
+ u32 *hid = h;
+ u32 *nid = n;
+ int i;
- default:
- bug("(hton): Unknown LSA");
- }
-};
+ for (i = 0; i < (len / sizeof(u32)); i++)
+ nid[i] = htonl(hid[i]);
+}
void
ntohlsab(void *n, void *h, u16 type, u16 len)
{
- unsigned int i;
- switch (type)
- {
- case LSA_T_RT:
- {
- struct ospf_lsa_rt *hrt, *nrt;
- struct ospf_lsa_rt_link *hrtl, *nrtl;
- u16 links;
-
- nrt = n;
- hrt = h;
-
-#ifdef OSPFv2
- hrt->options = ntohs(nrt->options);
- links = hrt->links = ntohs(nrt->links);
-#else /* OSPFv3 */
- hrt->options = ntohl(nrt->options);
- links = (len - sizeof(struct ospf_lsa_rt)) /
- sizeof(struct ospf_lsa_rt_link);
-#endif
-
- nrtl = (struct ospf_lsa_rt_link *) (nrt + 1);
- hrtl = (struct ospf_lsa_rt_link *) (hrt + 1);
- for (i = 0; i < links; i++)
- {
-#ifdef OSPFv2
- hrtl[i].id = ntohl(nrtl[i].id);
- hrtl[i].data = ntohl(nrtl[i].data);
- hrtl[i].type = nrtl[i].type;
- hrtl[i].notos = nrtl[i].notos;
- hrtl[i].metric = ntohs(nrtl[i].metric);
-#else /* OSPFv3 */
- hrtl[i].type = nrtl[i].type;
- hrtl[i].padding = 0;
- hrtl[i].metric = ntohs(nrtl[i].metric);
- hrtl[i].lif = ntohl(nrtl[i].lif);
- hrtl[i].nif = ntohl(nrtl[i].nif);
- hrtl[i].id = ntohl(nrtl[i].id);
-#endif
- }
- break;
- }
- case LSA_T_NET:
- case LSA_T_SUM_NET:
- case LSA_T_SUM_RT:
- case LSA_T_EXT:
-#ifdef OSPFv3
- case LSA_T_LINK:
- case LSA_T_PREFIX:
-#endif
- {
- u32 *hid, *nid;
-
- hid = h;
- nid = n;
+ u32 *nid = n;
+ u32 *hid = h;
+ int i;
- for (i = 0; i < (len / sizeof(u32)); i++)
- {
- hid[i] = ntohl(nid[i]);
- }
- break;
- }
- default:
- bug("(ntoh): Unknown LSA");
- }
-};
+ for (i = 0; i < (len / sizeof(u32)); i++)
+ hid[i] = ntohl(nid[i]);
+}
void
buf_dump(const char *hdr, const byte *buf, int blen)