Commit 3e2bd0f1 authored by Ondřej Filip's avatar Ondřej Filip

Md5 authentification added (unsested).

Packet receiving clean up.
parent 5236fb03
...@@ -24,7 +24,7 @@ CF_DECLS ...@@ -24,7 +24,7 @@ CF_DECLS
CF_KEYWORDS(OSPF, AREA, OSPF_METRIC1, OSPF_METRIC2, OSPF_TAG) CF_KEYWORDS(OSPF, AREA, OSPF_METRIC1, OSPF_METRIC2, OSPF_TAG)
CF_KEYWORDS(NEIGHBORS, RFC1583COMPAT, STUB, TICK, COST, RETRANSMIT) CF_KEYWORDS(NEIGHBORS, RFC1583COMPAT, STUB, TICK, COST, RETRANSMIT)
CF_KEYWORDS(HELLO, TRANSMIT, PRIORITY, DEAD, NONBROADCAST, POINTOPOINT, TYPE) CF_KEYWORDS(HELLO, TRANSMIT, PRIORITY, DEAD, NONBROADCAST, POINTOPOINT, TYPE)
CF_KEYWORDS(NONE, SIMPLE, AUTHENTICATION, PASSWORD, STRICT) CF_KEYWORDS(NONE, SIMPLE, AUTHENTICATION, STRICT)
CF_KEYWORDS(ELIGIBLE, POLL, NETWORKS, HIDDEN, VIRTUAL, LINK) CF_KEYWORDS(ELIGIBLE, POLL, NETWORKS, HIDDEN, VIRTUAL, LINK)
%type <t> opttext %type <t> opttext
...@@ -96,9 +96,9 @@ ospf_vlink_item: ...@@ -96,9 +96,9 @@ ospf_vlink_item:
| TRANSMIT DELAY expr { OSPF_PATT->inftransdelay = $3 ; if (($3<=0) || ($3>65535)) cf_error("Transmit delay must be in range 1-65535"); } | TRANSMIT DELAY expr { OSPF_PATT->inftransdelay = $3 ; if (($3<=0) || ($3>65535)) cf_error("Transmit delay must be in range 1-65535"); }
| WAIT expr { OSPF_PATT->waitint = $2 ; } | WAIT expr { OSPF_PATT->waitint = $2 ; }
| DEAD COUNT expr { OSPF_PATT->deadc = $3 ; if ($3<=1) cf_error("Dead count must be greater than one"); } | DEAD COUNT expr { OSPF_PATT->deadc = $3 ; if ($3<=1) cf_error("Dead count must be greater than one"); }
| AUTHENTICATION NONE { OSPF_PATT->autype = AU_NONE ; } | AUTHENTICATION NONE { OSPF_PATT->autype = OSPF_AUTH_NONE ; }
| AUTHENTICATION SIMPLE { OSPF_PATT->autype = AU_SIMPLE ; } | AUTHENTICATION SIMPLE { OSPF_PATT->autype = OSPF_AUTH_SIMPLE ; }
| PASSWORD TEXT { memcpy(OSPF_PATT->password, $2, 8); } | password_list {OSPF_PATT->passwords = $1; }
; ;
ospf_vlink_start: VIRTUAL LINK '{' ospf_vlink_start: VIRTUAL LINK '{'
...@@ -114,7 +114,7 @@ ospf_vlink_start: VIRTUAL LINK '{' ...@@ -114,7 +114,7 @@ ospf_vlink_start: VIRTUAL LINK '{'
OSPF_PATT->waitint = WAIT_DMH*HELLOINT_D; OSPF_PATT->waitint = WAIT_DMH*HELLOINT_D;
OSPF_PATT->deadc = DEADC_D; OSPF_PATT->deadc = DEADC_D;
OSPF_PATT->type = OSPF_IT_VLINK; OSPF_PATT->type = OSPF_IT_VLINK;
OSPF_PATT->autype = AU_NONE; OSPF_PATT->autype = OSPF_AUTH_NONE;
} }
; ;
...@@ -133,9 +133,9 @@ ospf_iface_item: ...@@ -133,9 +133,9 @@ ospf_iface_item:
| STRICT NONBROADCAST bool { OSPF_PATT->strictnbma = $3 ; } | STRICT NONBROADCAST bool { OSPF_PATT->strictnbma = $3 ; }
| STUB bool { OSPF_PATT->stub = $2 ; } | STUB bool { OSPF_PATT->stub = $2 ; }
| NEIGHBORS '{' ipa_list '}' | NEIGHBORS '{' ipa_list '}'
| AUTHENTICATION NONE { OSPF_PATT->autype = AU_NONE ; } | AUTHENTICATION NONE { OSPF_PATT->autype = OSPF_AUTH_NONE ; }
| AUTHENTICATION SIMPLE { OSPF_PATT->autype = AU_SIMPLE ; } | AUTHENTICATION SIMPLE { OSPF_PATT->autype = OSPF_AUTH_SIMPLE ; }
| PASSWORD TEXT { memcpy(OSPF_PATT->password, $2, 8); } | password_list {OSPF_PATT->passwords = $1; }
; ;
pref_list: pref_list:
...@@ -210,7 +210,7 @@ ospf_iface_start: ...@@ -210,7 +210,7 @@ ospf_iface_start:
OSPF_PATT->strictnbma = 0; OSPF_PATT->strictnbma = 0;
OSPF_PATT->stub = 0; OSPF_PATT->stub = 0;
init_list(&OSPF_PATT->nbma_list); init_list(&OSPF_PATT->nbma_list);
OSPF_PATT->autype = AU_NONE; OSPF_PATT->autype = OSPF_AUTH_NONE;
} }
; ;
......
...@@ -38,15 +38,14 @@ ospf_dbdes_send(struct ospf_neighbor *n) ...@@ -38,15 +38,14 @@ ospf_dbdes_send(struct ospf_neighbor *n)
n->myimms.bit.i = 1; n->myimms.bit.i = 1;
pkt = (struct ospf_dbdes_packet *) (ifa->ip_sk->tbuf); pkt = (struct ospf_dbdes_packet *) (ifa->ip_sk->tbuf);
op = (struct ospf_packet *) pkt; op = (struct ospf_packet *) pkt;
fill_ospf_pkt_hdr(ifa, pkt, DBDES_P); ospf_pkt_fill_hdr(ifa, pkt, DBDES_P);
pkt->iface_mtu = htons(ifa->iface->mtu); pkt->iface_mtu = htons(ifa->iface->mtu);
pkt->options = ifa->options; pkt->options = ifa->options;
pkt->imms = n->myimms; pkt->imms = n->myimms;
pkt->ddseq = htonl(n->dds); pkt->ddseq = htonl(n->dds);
length = sizeof(struct ospf_dbdes_packet); length = sizeof(struct ospf_dbdes_packet);
op->length = htons(length); op->length = htons(length);
ospf_pkt_finalize(ifa, op); ospf_send_to(ifa->ip_sk, n->ip, ifa);
ospf_send_to(ifa->ip_sk, length, n->ip);
OSPF_TRACE(D_PACKETS, "DB_DES (I) sent to %I via %s.", n->ip, OSPF_TRACE(D_PACKETS, "DB_DES (I) sent to %I via %s.", n->ip,
ifa->iface->name); ifa->iface->name);
break; break;
...@@ -63,12 +62,12 @@ ospf_dbdes_send(struct ospf_neighbor *n) ...@@ -63,12 +62,12 @@ ospf_dbdes_send(struct ospf_neighbor *n)
pkt = n->ldbdes; pkt = n->ldbdes;
op = (struct ospf_packet *) pkt; op = (struct ospf_packet *) pkt;
fill_ospf_pkt_hdr(ifa, pkt, DBDES_P); ospf_pkt_fill_hdr(ifa, pkt, DBDES_P);
pkt->iface_mtu = htons(ifa->iface->mtu); pkt->iface_mtu = htons(ifa->iface->mtu);
pkt->options = ifa->options; pkt->options = ifa->options;
pkt->ddseq = htonl(n->dds); pkt->ddseq = htonl(n->dds);
j = i = (ifa->iface->mtu - sizeof(struct ospf_dbdes_packet) - SIPH) / sizeof(struct ospf_lsa_header); /* Number of possible lsaheaders to send */ j = i = (ospf_pkt_maxsize(ifa) - sizeof(struct ospf_dbdes_packet)) / sizeof(struct ospf_lsa_header); /* Number of possible lsaheaders to send */
lsa = (n->ldbdes + sizeof(struct ospf_dbdes_packet)); lsa = (n->ldbdes + sizeof(struct ospf_dbdes_packet));
if (n->myimms.bit.m) if (n->myimms.bit.m)
...@@ -117,7 +116,6 @@ ospf_dbdes_send(struct ospf_neighbor *n) ...@@ -117,7 +116,6 @@ ospf_dbdes_send(struct ospf_neighbor *n)
sizeof(struct ospf_dbdes_packet); sizeof(struct ospf_dbdes_packet);
op->length = htons(length); op->length = htons(length);
ospf_pkt_finalize(ifa, op);
DBG("%s: DB_DES (M) prepared for %I.\n", p->name, n->ip); DBG("%s: DB_DES (M) prepared for %I.\n", p->name, n->ip);
} }
...@@ -136,7 +134,7 @@ ospf_dbdes_send(struct ospf_neighbor *n) ...@@ -136,7 +134,7 @@ ospf_dbdes_send(struct ospf_neighbor *n)
memcpy(ifa->ip_sk->tbuf, n->ldbdes, length); memcpy(ifa->ip_sk->tbuf, n->ldbdes, length);
/* Copy last sent packet again */ /* Copy last sent packet again */
ospf_send_to(ifa->ip_sk, length, n->ip); ospf_send_to(ifa->ip_sk, n->ip, n->ifa);
if(n->myimms.bit.ms) tm_start(n->rxmt_timer, n->ifa->rxmtint); /* Restart timer */ if(n->myimms.bit.ms) tm_start(n->rxmt_timer, n->ifa->rxmtint); /* Restart timer */
......
...@@ -200,7 +200,7 @@ ospf_hello_send(timer * timer, int poll, struct ospf_neighbor *dirn) ...@@ -200,7 +200,7 @@ ospf_hello_send(timer * timer, int poll, struct ospf_neighbor *dirn)
/* Now fill ospf_hello header */ /* Now fill ospf_hello header */
op = (struct ospf_packet *) pkt; op = (struct ospf_packet *) pkt;
fill_ospf_pkt_hdr(ifa, pkt, HELLO_P); ospf_pkt_fill_hdr(ifa, pkt, HELLO_P);
pkt->netmask = ipa_mkmask(ifa->iface->addr->pxlen); pkt->netmask = ipa_mkmask(ifa->iface->addr->pxlen);
ipa_hton(pkt->netmask); ipa_hton(pkt->netmask);
...@@ -218,6 +218,11 @@ ospf_hello_send(timer * timer, int poll, struct ospf_neighbor *dirn) ...@@ -218,6 +218,11 @@ ospf_hello_send(timer * timer, int poll, struct ospf_neighbor *dirn)
pp = (u32 *) (((u8 *) pkt) + sizeof(struct ospf_hello_packet)); pp = (u32 *) (((u8 *) pkt) + sizeof(struct ospf_hello_packet));
WALK_LIST(neigh, ifa->neigh_list) WALK_LIST(neigh, ifa->neigh_list)
{ {
if ((i+1) * sizeof(u32) + sizeof(struct ospf_hello_packet) > ospf_pkt_maxsize(ifa))
{
OSPF_TRACE(D_PACKETS, "Too many neighbors on the interface!");
break;
}
*(pp + i) = htonl(neigh->rid); *(pp + i) = htonl(neigh->rid);
i++; i++;
} }
...@@ -225,15 +230,12 @@ ospf_hello_send(timer * timer, int poll, struct ospf_neighbor *dirn) ...@@ -225,15 +230,12 @@ ospf_hello_send(timer * timer, int poll, struct ospf_neighbor *dirn)
length = sizeof(struct ospf_hello_packet) + i * sizeof(u32); length = sizeof(struct ospf_hello_packet) + i * sizeof(u32);
op->length = htons(length); op->length = htons(length);
ospf_pkt_finalize(ifa, op);
/* And finally send it :-) */
switch(ifa->type) switch(ifa->type)
{ {
case OSPF_IT_NBMA: case OSPF_IT_NBMA:
if (timer == NULL) /* Response to received hello */ if (timer == NULL) /* Response to received hello */
{ {
ospf_send_to(ifa->ip_sk, length, dirn->ip); ospf_send_to(ifa->ip_sk, dirn->ip, ifa);
} }
else else
{ {
...@@ -258,7 +260,7 @@ ospf_hello_send(timer * timer, int poll, struct ospf_neighbor *dirn) ...@@ -258,7 +260,7 @@ ospf_hello_send(timer * timer, int poll, struct ospf_neighbor *dirn)
if ((poll == 1) && (send)) if ((poll == 1) && (send))
{ {
if (toall || (meeli && nb->eligible)) if (toall || (meeli && nb->eligible))
ospf_send_to(ifa->ip_sk, length, nb->ip); ospf_send_to(ifa->ip_sk, nb->ip, ifa);
} }
} }
if (poll == 0) if (poll == 0)
...@@ -267,16 +269,16 @@ ospf_hello_send(timer * timer, int poll, struct ospf_neighbor *dirn) ...@@ -267,16 +269,16 @@ ospf_hello_send(timer * timer, int poll, struct ospf_neighbor *dirn)
{ {
if (toall || (n1->rid == ifa->drid) || (n1->rid == ifa->bdrid) || if (toall || (n1->rid == ifa->drid) || (n1->rid == ifa->bdrid) ||
(meeli && (n1->priority > 0))) (meeli && (n1->priority > 0)))
ospf_send_to(ifa->ip_sk, length, n1->ip); ospf_send_to(ifa->ip_sk, n1->ip, ifa);
} }
} }
} }
break; break;
case OSPF_IT_VLINK: case OSPF_IT_VLINK:
ospf_send_to(ifa->ip_sk, length, ifa->vip); ospf_send_to(ifa->ip_sk, ifa->vip, ifa);
break; break;
default: default:
sk_send(ifa->hello_sk, length); ospf_send_to(ifa->hello_sk, IPA_NONE, ifa);
} }
OSPF_TRACE(D_PACKETS, "Hello sent via %s", ifa->iface->name); OSPF_TRACE(D_PACKETS, "Hello sent via %s", ifa->iface->name);
} }
...@@ -373,7 +373,7 @@ ospf_iface_new(struct proto_ospf *po, struct iface *iface, struct ospf_area_conf ...@@ -373,7 +373,7 @@ ospf_iface_new(struct proto_ospf *po, struct iface *iface, struct ospf_area_conf
ifa->deadc = ip->deadc; ifa->deadc = ip->deadc;
ifa->stub = ip->stub; ifa->stub = ip->stub;
ifa->autype = ip->autype; ifa->autype = ip->autype;
memcpy(ifa->aukey, ip->password, 8); ifa->passwords = ip->passwords;
ifa->options = 2; /* FIXME what options? */ ifa->options = 2; /* FIXME what options? */
if (ip->type == OSPF_IT_UNDEF) if (ip->type == OSPF_IT_UNDEF)
......
...@@ -52,7 +52,7 @@ ospf_lsack_send(struct ospf_neighbor *n, int queue) ...@@ -52,7 +52,7 @@ ospf_lsack_send(struct ospf_neighbor *n, int queue)
pk = (struct ospf_lsack_packet *) sk->tbuf; pk = (struct ospf_lsack_packet *) sk->tbuf;
op = (struct ospf_packet *) sk->tbuf; op = (struct ospf_packet *) sk->tbuf;
fill_ospf_pkt_hdr(n->ifa, pk, LSACK_P); ospf_pkt_fill_hdr(n->ifa, pk, LSACK_P);
h = (struct ospf_lsa_header *) (pk + 1); h = (struct ospf_lsa_header *) (pk + 1);
while (!EMPTY_LIST(n->ackl[queue])) while (!EMPTY_LIST(n->ackl[queue]))
...@@ -65,7 +65,7 @@ ospf_lsack_send(struct ospf_neighbor *n, int queue) ...@@ -65,7 +65,7 @@ ospf_lsack_send(struct ospf_neighbor *n, int queue)
rem_node(NODE no); rem_node(NODE no);
mb_free(no); mb_free(no);
if ((i * sizeof(struct ospf_lsa_header) + if ((i * sizeof(struct ospf_lsa_header) +
sizeof(struct ospf_lsack_packet) + SIPH) > n->ifa->iface->mtu) sizeof(struct ospf_lsack_packet)) > ospf_pkt_maxsize(n->ifa))
{ {
if (!EMPTY_LIST(n->ackl[queue])) if (!EMPTY_LIST(n->ackl[queue]))
{ {
...@@ -73,24 +73,23 @@ ospf_lsack_send(struct ospf_neighbor *n, int queue) ...@@ -73,24 +73,23 @@ ospf_lsack_send(struct ospf_neighbor *n, int queue)
sizeof(struct ospf_lsack_packet) + sizeof(struct ospf_lsack_packet) +
i * sizeof(struct ospf_lsa_header); i * sizeof(struct ospf_lsa_header);
op->length = htons(len); op->length = htons(len);
ospf_pkt_finalize(n->ifa, op);
DBG("Sending and continuing! Len=%u\n", len); DBG("Sending and continuing! Len=%u\n", len);
if (ifa->type == OSPF_IT_BCAST) if (ifa->type == OSPF_IT_BCAST)
{ {
if ((ifa->state == OSPF_IS_DR) || (ifa->state == OSPF_IS_BACKUP)) if ((ifa->state == OSPF_IS_DR) || (ifa->state == OSPF_IS_BACKUP))
ospf_send_to(sk, len, AllSPFRouters); ospf_send_to(sk, AllSPFRouters, ifa);
else else
ospf_send_to(sk, len, AllDRouters); ospf_send_to(sk, AllDRouters, ifa);
} }
else else
{ {
if ((ifa->state == OSPF_IS_DR) || (ifa->state == OSPF_IS_BACKUP)) if ((ifa->state == OSPF_IS_DR) || (ifa->state == OSPF_IS_BACKUP))
ospf_send_to_agt(sk, len, ifa, NEIGHBOR_EXCHANGE); ospf_send_to_agt(sk, ifa, NEIGHBOR_EXCHANGE);
else else
ospf_send_to_bdr(sk, len, ifa); ospf_send_to_bdr(sk, ifa);
} }
fill_ospf_pkt_hdr(n->ifa, pk, LSACK_P); ospf_pkt_fill_hdr(n->ifa, pk, LSACK_P);
i = 0; i = 0;
} }
} }
...@@ -98,22 +97,21 @@ ospf_lsack_send(struct ospf_neighbor *n, int queue) ...@@ -98,22 +97,21 @@ ospf_lsack_send(struct ospf_neighbor *n, int queue)
len = sizeof(struct ospf_lsack_packet) + i * sizeof(struct ospf_lsa_header); len = sizeof(struct ospf_lsack_packet) + i * sizeof(struct ospf_lsa_header);
op->length = htons(len); op->length = htons(len);
ospf_pkt_finalize(n->ifa, op);
DBG("Sending! Len=%u\n", len); DBG("Sending! Len=%u\n", len);
if (ifa->type == OSPF_IT_BCAST) if (ifa->type == OSPF_IT_BCAST)
{ {
if ((ifa->state == OSPF_IS_DR) || (ifa->state == OSPF_IS_BACKUP)) if ((ifa->state == OSPF_IS_DR) || (ifa->state == OSPF_IS_BACKUP))
{ {
ospf_send_to(sk, len, AllSPFRouters); ospf_send_to(sk, AllSPFRouters, ifa);
} }
else else
{ {
ospf_send_to(sk, len, AllDRouters); ospf_send_to(sk, AllDRouters, ifa);
} }
} }
else else
{ {
ospf_send_to_agt(sk, len, ifa, NEIGHBOR_EXCHANGE); ospf_send_to_agt(sk, ifa, NEIGHBOR_EXCHANGE);
} }
} }
......
...@@ -23,7 +23,7 @@ ospf_lsreq_send(struct ospf_neighbor *n) ...@@ -23,7 +23,7 @@ ospf_lsreq_send(struct ospf_neighbor *n)
pk = (struct ospf_lsreq_packet *) n->ifa->ip_sk->tbuf; pk = (struct ospf_lsreq_packet *) n->ifa->ip_sk->tbuf;
op = (struct ospf_packet *) n->ifa->ip_sk->tbuf; op = (struct ospf_packet *) n->ifa->ip_sk->tbuf;
fill_ospf_pkt_hdr(n->ifa, pk, LSREQ_P); ospf_pkt_fill_hdr(n->ifa, pk, LSREQ_P);
sn = SHEAD(n->lsrql); sn = SHEAD(n->lsrql);
if (EMPTY_SLIST(n->lsrql)) if (EMPTY_SLIST(n->lsrql))
...@@ -33,7 +33,7 @@ ospf_lsreq_send(struct ospf_neighbor *n) ...@@ -33,7 +33,7 @@ ospf_lsreq_send(struct ospf_neighbor *n)
return; return;
} }
i = j = (n->ifa->iface->mtu - SIPH - sizeof(struct ospf_lsreq_packet)) / i = j = (ospf_pkt_maxsize(n->ifa) - sizeof(struct ospf_lsreq_packet)) /
sizeof(struct ospf_lsreq_header); sizeof(struct ospf_lsreq_header);
lsh = (struct ospf_lsreq_header *) (pk + 1); lsh = (struct ospf_lsreq_header *) (pk + 1);
...@@ -59,8 +59,7 @@ ospf_lsreq_send(struct ospf_neighbor *n) ...@@ -59,8 +59,7 @@ ospf_lsreq_send(struct ospf_neighbor *n)
sizeof(struct ospf_lsreq_packet) + (j - sizeof(struct ospf_lsreq_packet) + (j -
i) * sizeof(struct ospf_lsreq_header); i) * sizeof(struct ospf_lsreq_header);
op->length = htons(length); op->length = htons(length);
ospf_pkt_finalize(n->ifa, op); ospf_send_to(n->ifa->ip_sk, n->ip, n->ifa);
ospf_send_to(n->ifa->ip_sk, length, n->ip);
OSPF_TRACE(D_PACKETS, "LS request sent to: %I", n->rid); OSPF_TRACE(D_PACKETS, "LS request sent to: %I", n->rid);
} }
......
...@@ -160,7 +160,7 @@ ospf_lsupd_flood(struct ospf_neighbor *n, struct ospf_lsa_header *hn, ...@@ -160,7 +160,7 @@ ospf_lsupd_flood(struct ospf_neighbor *n, struct ospf_lsa_header *hn,
pk = (struct ospf_lsupd_packet *) sk->tbuf; pk = (struct ospf_lsupd_packet *) sk->tbuf;
op = (struct ospf_packet *) sk->tbuf; op = (struct ospf_packet *) sk->tbuf;
fill_ospf_pkt_hdr(ifa, pk, LSUPD_P); ospf_pkt_fill_hdr(ifa, pk, LSUPD_P);
pk->lsano = htonl(1); pk->lsano = htonl(1);
lh = (struct ospf_lsa_header *) (pk + 1); lh = (struct ospf_lsa_header *) (pk + 1);
...@@ -191,23 +191,22 @@ ospf_lsupd_flood(struct ospf_neighbor *n, struct ospf_lsa_header *hn, ...@@ -191,23 +191,22 @@ ospf_lsupd_flood(struct ospf_neighbor *n, struct ospf_lsa_header *hn,
lh->age = htons(age); lh->age = htons(age);
op->length = htons(len); op->length = htons(len);
ospf_pkt_finalize(ifa, op);
OSPF_TRACE(D_PACKETS, "LS upd flooded via %s", ifa->iface->name); OSPF_TRACE(D_PACKETS, "LS upd flooded via %s", ifa->iface->name);
if (ifa->type == OSPF_IT_NBMA) if (ifa->type == OSPF_IT_NBMA)
{ {
if ((ifa->state == OSPF_IS_BACKUP) || (ifa->state == OSPF_IS_DR)) if ((ifa->state == OSPF_IS_BACKUP) || (ifa->state == OSPF_IS_DR))
ospf_send_to_agt(sk, len, ifa, NEIGHBOR_EXCHANGE); ospf_send_to_agt(sk, ifa, NEIGHBOR_EXCHANGE);
else else
ospf_send_to_bdr(sk, len, ifa); ospf_send_to_bdr(sk, ifa);
} }
else else
{ {
if ((ifa->state == OSPF_IS_BACKUP) || (ifa->state == OSPF_IS_DR) || if ((ifa->state == OSPF_IS_BACKUP) || (ifa->state == OSPF_IS_DR) ||
(ifa->type == OSPF_IT_PTP)) (ifa->type == OSPF_IT_PTP))
ospf_send_to(sk, len, AllSPFRouters); ospf_send_to(sk, AllSPFRouters, ifa);
else else
ospf_send_to(sk, len, AllDRouters); ospf_send_to(sk, AllDRouters, ifa);
} }
} }
} }
...@@ -234,8 +233,8 @@ ospf_lsupd_send_list(struct ospf_neighbor *n, list * l) ...@@ -234,8 +233,8 @@ ospf_lsupd_send_list(struct ospf_neighbor *n, list * l)
DBG("LSupd: 1st packet\n"); DBG("LSupd: 1st packet\n");
fill_ospf_pkt_hdr(n->ifa, pk, LSUPD_P); ospf_pkt_fill_hdr(n->ifa, pk, LSUPD_P);
len = SIPH + sizeof(struct ospf_lsupd_packet); len = sizeof(struct ospf_lsupd_packet);
lsano = 0; lsano = 0;
pktpos = (pk + 1); pktpos = (pk + 1);
...@@ -247,18 +246,17 @@ ospf_lsupd_send_list(struct ospf_neighbor *n, list * l) ...@@ -247,18 +246,17 @@ ospf_lsupd_send_list(struct ospf_neighbor *n, list * l)
DBG("Sending ID=%I, Type=%u, RT=%I Sn: 0x%x Age: %u\n", DBG("Sending ID=%I, Type=%u, RT=%I Sn: 0x%x Age: %u\n",
llsh->lsh.id, llsh->lsh.type, llsh->lsh.rt, en->lsa.sn, en->lsa.age); llsh->lsh.id, llsh->lsh.type, llsh->lsh.rt, en->lsa.sn, en->lsa.age);
if (((u32) (len + en->lsa.length)) > n->ifa->iface->mtu) if (((u32) (len + en->lsa.length)) > ospf_pkt_maxsize(n->ifa))
{ {
pk->lsano = htonl(lsano); pk->lsano = htonl(lsano);
op->length = htons(len - SIPH); op->length = htons(len);
ospf_pkt_finalize(n->ifa, op);
ospf_send_to(n->ifa->ip_sk, len - SIPH, n->ip); ospf_send_to(n->ifa->ip_sk, n->ip, n->ifa);
OSPF_TRACE(D_PACKETS, "LS upd sent to %I (%d LSAs)", n->ip, lsano); OSPF_TRACE(D_PACKETS, "LS upd sent to %I (%d LSAs)", n->ip, lsano);
DBG("LSupd: next packet\n"); DBG("LSupd: next packet\n");
fill_ospf_pkt_hdr(n->ifa, pk, LSUPD_P); ospf_pkt_fill_hdr(n->ifa, pk, LSUPD_P);
len = SIPH + sizeof(struct ospf_lsupd_packet); len = sizeof(struct ospf_lsupd_packet);
lsano = 0; lsano = 0;
pktpos = (pk + 1); pktpos = (pk + 1);
} }
...@@ -273,11 +271,10 @@ ospf_lsupd_send_list(struct ospf_neighbor *n, list * l) ...@@ -273,11 +271,10 @@ ospf_lsupd_send_list(struct ospf_neighbor *n, list * l)
if (lsano > 0) if (lsano > 0)
{ {
pk->lsano = htonl(lsano); pk->lsano = htonl(lsano);
op->length = htons(len - SIPH); op->length = htons(len);
ospf_pkt_finalize(n->ifa, op);
OSPF_TRACE(D_PACKETS, "LS upd sent to %I (%d LSAs)", n->ip, lsano); OSPF_TRACE(D_PACKETS, "LS upd sent to %I (%d LSAs)", n->ip, lsano);
ospf_send_to(n->ifa->ip_sk, len - SIPH, n->ip); ospf_send_to(n->ifa->ip_sk, n->ip, n->ifa);
} }
} }
......
...@@ -41,6 +41,7 @@ ospf_neighbor_new(struct ospf_iface *ifa) ...@@ -41,6 +41,7 @@ ospf_neighbor_new(struct ospf_iface *ifa)
n->ifa = ifa; n->ifa = ifa;
add_tail(&ifa->neigh_list, NODE n); add_tail(&ifa->neigh_list, NODE n);
n->adj = 0; n->adj = 0;
n->csn = 0;
n->ldbdes = mb_allocz(pool, ifa->iface->mtu); n->ldbdes = mb_allocz(pool, ifa->iface->mtu);
n->state = NEIGHBOR_DOWN; n->state = NEIGHBOR_DOWN;
......
...@@ -675,12 +675,7 @@ ospf_reconfigure(struct proto *p, struct proto_config *c) ...@@ -675,12 +675,7 @@ ospf_reconfigure(struct proto *p, struct proto_config *c)
"Changing authentication type on interface %s", "Changing authentication type on interface %s",
ifa->iface->name); ifa->iface->name);
} }
if (strncmp(ip1->password, ip2->password, 8) != 0) /* FIXME Add *passwords */
{
memcpy(ifa->aukey, ip2->password, 8);
OSPF_TRACE(D_EVENTS,
"Changing password on interface %s", ifa->iface->name);
}
/* RXMT */ /* RXMT */
if (ip1->rxmtint != ip2->rxmtint) if (ip1->rxmtint != ip2->rxmtint)
......
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
#ifndef _BIRD_OSPF_H_ #ifndef _BIRD_OSPF_H_
#define _BIRD_OSPF_H_ #define _BIRD_OSPF_H_
#define SIPH SIZE_OF_IP_HEADER
#define MAXNETS 10 #define MAXNETS 10
#ifdef LOCAL_DEBUG #ifdef LOCAL_DEBUG
#define OSPF_FORCE_DEBUG 1 #define OSPF_FORCE_DEBUG 1
...@@ -122,8 +121,9 @@ struct ospf_iface ...@@ -122,8 +121,9 @@ struct ospf_iface
ip_addr vip; /* IP of peer of virtual link */ ip_addr vip; /* IP of peer of virtual link */
struct ospf_area *voa; /* Area wich the vlink goes through */ struct ospf_area *voa; /* Area wich the vlink goes through */
u16 autype; u16 autype;
u8 aukey[8];
u8 options; u8 options;
list *passwords;
u32 csn; /* Crypt seq num. that will be sent net */
ip_addr drip; /* Designated router */ ip_addr drip; /* Designated router */
u32 drid; u32 drid;
ip_addr bdrip; /* Backup DR */ ip_addr bdrip; /* Backup DR */
...@@ -168,6 +168,20 @@ struct ospf_iface ...@@ -168,6 +168,20 @@ struct ospf_iface
list nbma_list; list nbma_list;
}; };
struct ospf_md5
{
u16 zero;
u8 keyid;
u8 len;
u32 csn;
};
union ospf_auth
{
u8 password[8];
struct ospf_md5 md5;
};
struct ospf_packet struct ospf_packet
{ {
u8 version; u8 version;
...@@ -183,7 +197,7 @@ struct ospf_packet ...@@ -183,7 +197,7 @@ struct ospf_packet
#define BACKBONE 0 #define BACKBONE 0
u16 checksum; u16 checksum;
u16 autype; u16 autype;
u8 authetication[8]; union ospf_auth u;
}; };
struct ospf_hello_packet struct ospf_hello_packet
...@@ -437,6 +451,7 @@ struct ospf_neighbor ...@@ -437,6 +451,7 @@ struct ospf_neighbor
#define ACKL_DIRECT 0 #define ACKL_DIRECT 0
#define ACKL_DELAY 1 #define ACKL_DELAY 1
timer *ackd_timer; /* Delayed ack timer */ timer *ackd_timer; /* Delayed ack timer */
u32 csn; /* Last received crypt seq number (for MD5) */
}; };
/* Definitions for interface state machine */ /* Definitions for interface state machine */
...@@ -512,11 +527,11 @@ struct ospf_iface_patt ...@@ -512,11 +527,11 @@ struct ospf_iface_patt
u32 strictnbma; u32 strictnbma;
u32 stub; u32 stub;
u32 vid; u32 vid;
/* must be in network byte order */ #define OSPF_AUTH_NONE 0
#define AU_NONE htons(0) #define OSPF_AUTH_SIMPLE 1
#define AU_SIMPLE htons(1) #define OSPF_AUTH_CRYPT 2
#define AU_CRYPT htons(2) #define OSPF_AUTH_CRYPT_SIZE 16
u8 password[8]; list *passwords;
list nbma_list; list nbma_list;
}; };
......
/* /*
* BIRD -- OSPF * BIRD -- OSPF
* *
* (c) 1999 - 2003 Ondrej Filip <feela@network.cz> * (c) 1999--2004 Ondrej Filip <feela@network.cz>
* *
* Can be freely distributed and used under the terms of the GNU GPL. * Can be freely distributed and used under the terms of the GNU GPL.
*/ */
#include "ospf.h" #include "ospf.h"
#include "nest/password.h"
#include "lib/md5.h"
void void
fill_ospf_pkt_hdr(struct ospf_iface *ifa, void *buf, u8 h_type) ospf_pkt_fill_hdr(struct ospf_iface *ifa, void *buf, u8 h_type)
{ {
struct ospf_packet *pkt; struct ospf_packet *pkt;
struct proto *p; struct proto *p;
...@@ -28,45 +30,167 @@ fill_ospf_pkt_hdr(struct ospf_iface *ifa, void *buf, u8 h_type) ...@@ -28,45 +30,167 @@ fill_ospf_pkt_hdr(struct ospf_iface *ifa, void *buf, u8 h_type)
pkt->checksum = 0; pkt->checksum = 0;
} }
unsigned
ospf_pkt_maxsize(struct ospf_iface *ifa)
{
return ifa->iface->mtu - SIZE_OF_IP_HEADER -
((ifa->autype == OSPF_AUTH_CRYPT) ? OSPF_AUTH_CRYPT_SIZE : 0);
}
void void
ospf_tx_authenticate(struct ospf_iface *ifa, struct ospf_packet *pkt) ospf_pkt_finalize(struct ospf_iface *ifa, struct ospf_packet *pkt)
{ {
struct proto_ospf *po = ifa->proto;
struct proto *p = &po->proto;
struct password_item *passwd = password_find (ifa->passwords);
void *tail;
struct MD5Context ctxt;
char password[OSPF_AUTH_CRYPT_SIZE];
pkt->autype = htons(ifa->autype); pkt->autype = htons(ifa->autype);
memcpy(pkt->authetication, ifa->aukey, 8);
return; switch(ifa->autype)
{
case OSPF_AUTH_NONE:
case OSPF_AUTH_SIMPLE:
pkt->checksum = ipsum_calculate(pkt, sizeof(struct ospf_packet) - 8,
(pkt + 1),
ntohs(pkt->length) -
sizeof(struct ospf_packet), NULL);
password_cpy(pkt->u.password, passwd->password, 8);