summaryrefslogtreecommitdiffstats
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
parentbe862406627da3bd1facea9309b3f32e67422eab (diff)
downloadbird-c15e569065e80f91b4c9c77b86640aac72aa0a47.tar
bird-c15e569065e80f91b4c9c77b86640aac72aa0a47.zip
Make endianity swapping simpler.
-rw-r--r--proto/ospf/lsalib.c149
-rw-r--r--proto/ospf/ospf.h75
-rw-r--r--proto/ospf/topology.c10
3 files changed, 42 insertions, 192 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)
diff --git a/proto/ospf/ospf.h b/proto/ospf/ospf.h
index 4bcb7a0..d85ebdc 100644
--- a/proto/ospf/ospf.h
+++ b/proto/ospf/ospf.h
@@ -389,17 +389,28 @@ struct ospf_lsa_header
struct ospf_lsa_rt
{
+#ifdef CPU_BIG_ENDIAN
u16 options; /* VEB flags only */
u16 links;
+#else
+ u16 links;
+ u16 options; /* VEB flags only */
+#endif
};
struct ospf_lsa_rt_link
{
u32 id;
u32 data;
+#ifdef CPU_BIG_ENDIAN
u8 type;
- u8 notos;
+ u8 padding;
u16 metric;
+#else
+ u16 metric;
+ u8 padding;
+ u8 type;
+#endif
};
struct ospf_lsa_net
@@ -438,9 +449,15 @@ struct ospf_lsa_rt
struct ospf_lsa_rt_link
{
+#ifdef CPU_BIG_ENDIAN
u8 type;
u8 padding;
u16 metric;
+#else
+ u16 metric;
+ u8 padding;
+ u8 type;
+#endif
u32 lif; /* Local interface ID */
u32 nif; /* Neighbor interface ID */
u32 id; /* Neighbor router ID */
@@ -481,8 +498,13 @@ struct ospf_lsa_link
struct ospf_lsa_prefix
{
+#ifdef CPU_BIG_ENDIAN
u16 pxcount;
u16 ref_type;
+#else
+ u16 ref_type;
+ u16 pxcount;
+#endif
u32 ref_id;
u32 ref_rt;
u32 rest[];
@@ -514,57 +536,6 @@ static inline unsigned lsa_net_count(struct ospf_lsa_header *lsa)
}
-/*
-struct ospf_lsa_ext_etos
-{
-#ifdef CPU_BIG_ENDIAN
- u8 ebit:1;
- u8 tos:7;
- u8 padding1;
- u16 padding2;
-#else
- u16 padding2;
- u8 padding1;
- u8 tos:7;
- u8 ebit:1;
-#endif
-};
-
-
-struct ospf_lsa_sum_tos
-{
-#ifdef CPU_BIG_ENDIAN
- u8 tos;
- u8 padding1;
- u16 padding2;
-#else
- u16 padding2;
- u8 padding1;
- u8 tos;
-#endif
-};
-
-union ospf_lsa_sum_tm
-{
- struct ospf_lsa_sum_tos tos;
- u32 metric;
-};
-
-union ospf_lsa_ext_etm
-{
- struct ospf_lsa_ext_etos etos;
- u32 metric;
-};
-
-struct ospf_lsa_ext_tos
-{
- union ospf_lsa_ext_etm etm;
- ip_addr fwaddr;
- u32 tag;
-};
-
-*/
-
struct ospf_lsreq_header
{
u32 type;
diff --git a/proto/ospf/topology.c b/proto/ospf/topology.c
index cadf4ea..47d8367 100644
--- a/proto/ospf/topology.c
+++ b/proto/ospf/topology.c
@@ -211,7 +211,7 @@ originate_rt_lsa_body(struct ospf_area *oa, u16 *length)
ln->data = (ifa->iface->addr->flags & IA_UNNUMBERED) ?
ifa->iface->index : ipa_to_u32(ifa->iface->addr->ip);
ln->metric = ifa->cost;
- ln->notos = 0;
+ ln->padding = 0;
i++;
master = 1;
}
@@ -226,7 +226,7 @@ originate_rt_lsa_body(struct ospf_area *oa, u16 *length)
ln->id = ipa_to_u32(ifa->drip);
ln->data = ipa_to_u32(ifa->iface->addr->ip);
ln->metric = ifa->cost;
- ln->notos = 0;
+ ln->padding = 0;
i++;
master = 1;
}
@@ -241,7 +241,7 @@ originate_rt_lsa_body(struct ospf_area *oa, u16 *length)
ln->id = neigh->rid;
ln->data = ipa_to_u32(ifa->iface->addr->ip);
ln->metric = ifa->cost;
- ln->notos = 0;
+ ln->padding = 0;
i++;
master = 1;
}
@@ -268,7 +268,7 @@ originate_rt_lsa_body(struct ospf_area *oa, u16 *length)
ln->id = ipa_to_u32(a->prefix);
ln->data = ipa_to_u32(ipa_mkmask(a->pxlen));
ln->metric = ifa->cost;
- ln->notos = 0;
+ ln->padding = 0;
i++;
}
}
@@ -282,7 +282,7 @@ originate_rt_lsa_body(struct ospf_area *oa, u16 *length)
ln->id = ipa_to_u32(sn->px.addr);
ln->data = ipa_to_u32(ipa_mkmask(sn->px.len));
ln->metric = sn->cost;
- ln->notos = 0;
+ ln->padding = 0;
i++;
}