diff options
author | 2008-12-30 21:31:54 +0000 | |
---|---|---|
committer | 2008-12-30 21:31:54 +0000 | |
commit | d913b22e862af5ef84fb632c72944c214e43e87a (patch) | |
tree | f2768d066a54c9482ba6e6453c49ee2fc76e4154 | |
parent | Implement the mach_desc hypervisor call. (diff) | |
download | wireguard-openbsd-d913b22e862af5ef84fb632c72944c214e43e87a.tar.xz wireguard-openbsd-d913b22e862af5ef84fb632c72944c214e43e87a.zip |
First try at originating Link (type-8) LSA. Code is wrong and the initial
LSA is lost in lsa_flood. Put this in because it goes in the right direction
and ospf6d is work in progress. Add necessary framework so that we can print
Link LSA in ospf6ctl.
Diff mostly from stsp@ ospf6ctl part by myself
-rw-r--r-- | usr.sbin/ospf6d/control.c | 3 | ||||
-rw-r--r-- | usr.sbin/ospf6d/interface.c | 6 | ||||
-rw-r--r-- | usr.sbin/ospf6d/ospf6.h | 20 | ||||
-rw-r--r-- | usr.sbin/ospf6d/ospf6d.h | 3 | ||||
-rw-r--r-- | usr.sbin/ospf6d/ospfe.c | 92 | ||||
-rw-r--r-- | usr.sbin/ospf6d/ospfe.h | 3 | ||||
-rw-r--r-- | usr.sbin/ospf6d/rde.c | 3 | ||||
-rw-r--r-- | usr.sbin/ospf6d/rde_lsdb.c | 6 |
8 files changed, 120 insertions, 16 deletions
diff --git a/usr.sbin/ospf6d/control.c b/usr.sbin/ospf6d/control.c index 57cb27b7362..824f17370c8 100644 --- a/usr.sbin/ospf6d/control.c +++ b/usr.sbin/ospf6d/control.c @@ -1,4 +1,4 @@ -/* $OpenBSD: control.c,v 1.4 2008/01/31 12:17:35 henning Exp $ */ +/* $OpenBSD: control.c,v 1.5 2008/12/30 21:31:54 claudio Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -248,6 +248,7 @@ control_dispatch_imsg(int fd, short event, void *bula) break; case IMSG_CTL_SHOW_DATABASE: case IMSG_CTL_SHOW_DB_EXT: + case IMSG_CTL_SHOW_DB_LINK: case IMSG_CTL_SHOW_DB_NET: case IMSG_CTL_SHOW_DB_RTR: case IMSG_CTL_SHOW_DB_SELF: diff --git a/usr.sbin/ospf6d/interface.c b/usr.sbin/ospf6d/interface.c index 76d859aa050..61befca1d29 100644 --- a/usr.sbin/ospf6d/interface.c +++ b/usr.sbin/ospf6d/interface.c @@ -1,4 +1,4 @@ -/* $OpenBSD: interface.c,v 1.8 2007/12/13 08:54:05 claudio Exp $ */ +/* $OpenBSD: interface.c,v 1.9 2008/12/30 21:31:54 claudio Exp $ */ /* * Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org> @@ -139,8 +139,10 @@ if_fsm(struct iface *iface, enum iface_event event) if (new_state != 0) iface->state = new_state; - if (iface->state != old_state) + if (iface->state != old_state) { orig_rtr_lsa(iface); + orig_link_lsa(iface); + } if (old_state & (IF_STA_MULTI | IF_STA_POINTTOPOINT) && (iface->state & (IF_STA_MULTI | IF_STA_POINTTOPOINT)) == 0) diff --git a/usr.sbin/ospf6d/ospf6.h b/usr.sbin/ospf6d/ospf6.h index c2ee355249c..7c5eba3bde2 100644 --- a/usr.sbin/ospf6d/ospf6.h +++ b/usr.sbin/ospf6d/ospf6.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ospf6.h,v 1.11 2008/12/28 21:22:14 claudio Exp $ */ +/* $OpenBSD: ospf6.h,v 1.12 2008/12/30 21:31:54 claudio Exp $ */ /* * Copyright (c) 2004, 2005, 2007 Esben Norby <norby@openbsd.org> @@ -197,11 +197,17 @@ struct ls_upd_hdr { #define OSPF_RTR_x 0x08 /* ignored, should be 0 */ #define OSPF_RTR_Nt 0x10 +#define OSPF_PREFIX_NU 0x01 +#define OSPF_PREFIX_LA 0x02 +#define OSPF_PREFIX_x 0x04 /* ignored, should be 0 */ +#define OSPF_PREFIX_P 0x08 +#define OSPF_PREFIX_DN 0x10 + struct lsa_prefix { - struct in6_addr prefix; - u_int16_t metric; u_int8_t prefixlen; u_int8_t options; + u_int16_t metric; + struct in6_addr prefix; }; struct lsa_rtr { @@ -232,7 +238,7 @@ struct lsa_prefix_sum { }; struct lsa_rtr_sum { - u_int32_t options; /* lower 24bit options */ + u_int32_t opts; /* lower 24bit options */ u_int32_t metric; /* only lower 24 bit */ u_int32_t dest_rtr_id; }; @@ -245,10 +251,10 @@ struct lsa_asext { }; struct lsa_link { - u_int32_t options; /* rtr pri & 24bit options */ + u_int32_t opts; /* rtr pri & 24bit options */ struct in6_addr lladdr; u_int32_t numprefix; - /* + numprefix prefix */ + /* + numprefix * lsa_prefix */ }; struct lsa_intra_prefix { @@ -256,7 +262,7 @@ struct lsa_intra_prefix { u_int16_t ref_type; u_int32_t ref_lsid; u_int32_t ref_adv_rtr; - /* + numprefix prefix */ + /* + numprefix * lsa_prefix */ }; struct lsa_hdr { diff --git a/usr.sbin/ospf6d/ospf6d.h b/usr.sbin/ospf6d/ospf6d.h index 9b817e8eb39..a5f312018d8 100644 --- a/usr.sbin/ospf6d/ospf6d.h +++ b/usr.sbin/ospf6d/ospf6d.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ospf6d.h,v 1.12 2007/12/13 08:54:05 claudio Exp $ */ +/* $OpenBSD: ospf6d.h,v 1.13 2008/12/30 21:31:54 claudio Exp $ */ /* * Copyright (c) 2004, 2007 Esben Norby <norby@openbsd.org> @@ -103,6 +103,7 @@ enum imsg_type { IMSG_CTL_SHOW_INTERFACE, IMSG_CTL_SHOW_DATABASE, IMSG_CTL_SHOW_DB_EXT, + IMSG_CTL_SHOW_DB_LINK, IMSG_CTL_SHOW_DB_NET, IMSG_CTL_SHOW_DB_RTR, IMSG_CTL_SHOW_DB_SELF, diff --git a/usr.sbin/ospf6d/ospfe.c b/usr.sbin/ospf6d/ospfe.c index 8d91c933a60..bfa6b68cc89 100644 --- a/usr.sbin/ospf6d/ospfe.c +++ b/usr.sbin/ospf6d/ospfe.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ospfe.c,v 1.11 2008/12/28 21:22:14 claudio Exp $ */ +/* $OpenBSD: ospfe.c,v 1.12 2008/12/30 21:31:54 claudio Exp $ */ /* * Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org> @@ -468,7 +468,7 @@ ospfe_dispatch_rde(int fd, short event, void *bula) ref = lsa_cache_add(imsg.data, l); - if (lsa_hdr.type == LSA_TYPE_EXTERNAL) { + if (lsa_hdr.type == htons(LSA_TYPE_EXTERNAL)) { /* * flood on all areas but stub areas and * virtual links @@ -482,6 +482,13 @@ ospfe_dispatch_rde(int fd, short event, void *bula) &lsa_hdr, imsg.data); } } + } else if (lsa_hdr.type == htons(LSA_TYPE_LINK)) { + /* + * flood on interface only + */ + log_debug("flooding link LSA"); + noack += lsa_flood(nbr->iface, nbr, + &lsa_hdr, imsg.data); } else { /* * flood on all area interfaces on @@ -620,6 +627,7 @@ ospfe_dispatch_rde(int fd, short event, void *bula) case IMSG_CTL_END: case IMSG_CTL_SHOW_DATABASE: case IMSG_CTL_SHOW_DB_EXT: + case IMSG_CTL_SHOW_DB_LINK: case IMSG_CTL_SHOW_DB_NET: case IMSG_CTL_SHOW_DB_RTR: case IMSG_CTL_SHOW_DB_SELF: @@ -983,6 +991,86 @@ orig_net_lsa(struct iface *iface) buf_free(buf); } +void +orig_link_lsa(struct iface *iface) +{ + struct lsa_hdr lsa_hdr; + struct lsa_link lsa_link; + struct lsa_prefix lsa_prefix; + struct buf *buf; + struct iface_addr *ia; + struct in6_addr prefix; + unsigned int num_prefix = 0; + u_int16_t chksum; + u_int32_t options; + + log_debug("orig_link_lsa: interface %s", iface->name); + + if (iface->type == IF_TYPE_VIRTUALLINK) + return; + + if ((iface->state & IF_STA_MULTI) == 0) + return; + + /* XXX READ_BUF_SIZE */ + if ((buf = buf_dynamic(sizeof(lsa_hdr) + sizeof(lsa_link), + READ_BUF_SIZE)) == NULL) + fatal("orig_link_lsa"); + + /* reserve space for LSA header and LSA link header */ + if (buf_reserve(buf, sizeof(lsa_hdr) + sizeof(lsa_link)) == NULL) + fatal("orig_link_lsa: buf_reserve failed"); + + /* link-local address, and all prefixes configured on interface */ + TAILQ_FOREACH(ia, &iface->ifa_list, entry) { + if (IN6_IS_ADDR_LINKLOCAL(&ia->addr)) { + log_debug("orig_link_lsa: link local address %s", + log_in6addr(&ia->addr)); + lsa_link.lladdr = ia->addr; + continue; + } + + lsa_prefix.prefixlen = ia->prefixlen; + lsa_prefix.options = 0; + lsa_prefix.metric = 0; + inet6applymask(&prefix, &ia->addr, ia->prefixlen); + lsa_prefix.prefix = prefix; + log_debug("orig_link_lsa: prefix %s", log_in6addr(&prefix)); + if (buf_add(buf, &lsa_prefix, sizeof(lsa_prefix))) + fatal("orig_link_lsa: buf_add failed"); + num_prefix++; + } + + /* LSA link header (lladdr has already been filled in above) */ + LSA_24_SETHI(lsa_link.opts, iface->priority); + options = area_ospf_options(area_find(oeconf, iface->area_id)); + LSA_24_SETLO(lsa_link.opts, options); + lsa_link.opts = htonl(lsa_link.opts); + lsa_link.numprefix = htonl(num_prefix); + memcpy(buf_seek(buf, sizeof(lsa_hdr), sizeof(lsa_link)), + &lsa_link, sizeof(lsa_link)); + + /* LSA header */ + lsa_hdr.age = htons(DEFAULT_AGE); + lsa_hdr.type = htons(LSA_TYPE_LINK); + /* for link LSAs, the link state ID equals the interface ID */ + lsa_hdr.ls_id = htonl(iface->ifindex); + lsa_hdr.adv_rtr = oeconf->rtr_id.s_addr; + lsa_hdr.seq_num = htonl(INIT_SEQ_NUM); + lsa_hdr.len = htons(buf->wpos); + lsa_hdr.ls_chksum = 0; /* updated later */ + memcpy(buf_seek(buf, 0, sizeof(lsa_hdr)), &lsa_hdr, sizeof(lsa_hdr)); + + chksum = htons(iso_cksum(buf->buf, buf->wpos, LS_CKSUM_OFFSET)); + memcpy(buf_seek(buf, LS_CKSUM_OFFSET, sizeof(chksum)), + &chksum, sizeof(chksum)); + + imsg_compose(ibuf_rde, IMSG_LS_UPD, iface->self->peerid, 0, + buf->buf, buf->wpos); + + buf_free(buf); +} + u_int32_t ospfe_router_id(void) { diff --git a/usr.sbin/ospf6d/ospfe.h b/usr.sbin/ospf6d/ospfe.h index 5f4eb8316c1..6017c7917a6 100644 --- a/usr.sbin/ospf6d/ospfe.h +++ b/usr.sbin/ospf6d/ospfe.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ospfe.h,v 1.10 2008/12/28 17:56:16 claudio Exp $ */ +/* $OpenBSD: ospfe.h,v 1.11 2008/12/30 21:31:54 claudio Exp $ */ /* * Copyright (c) 2004, 2005 Esben Norby <norby@openbsd.org> @@ -122,6 +122,7 @@ void ospfe_iface_ctl(struct ctl_conn *, unsigned int); void ospfe_nbr_ctl(struct ctl_conn *); void orig_rtr_lsa(struct iface *); void orig_net_lsa(struct iface *); +void orig_link_lsa(struct iface *); void ospfe_demote_area(struct area *, int); void ospfe_demote_iface(struct iface *, int); diff --git a/usr.sbin/ospf6d/rde.c b/usr.sbin/ospf6d/rde.c index 30a8925d048..cdbc3a04031 100644 --- a/usr.sbin/ospf6d/rde.c +++ b/usr.sbin/ospf6d/rde.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rde.c,v 1.12 2008/12/28 18:43:53 claudio Exp $ */ +/* $OpenBSD: rde.c,v 1.13 2008/12/30 21:31:54 claudio Exp $ */ /* * Copyright (c) 2004, 2005 Claudio Jeker <claudio@openbsd.org> @@ -488,6 +488,7 @@ rde_dispatch_imsg(int fd, short event, void *bula) break; case IMSG_CTL_SHOW_DATABASE: case IMSG_CTL_SHOW_DB_EXT: + case IMSG_CTL_SHOW_DB_LINK: case IMSG_CTL_SHOW_DB_NET: case IMSG_CTL_SHOW_DB_RTR: case IMSG_CTL_SHOW_DB_SELF: diff --git a/usr.sbin/ospf6d/rde_lsdb.c b/usr.sbin/ospf6d/rde_lsdb.c index ad1d0d8510e..c200f69f809 100644 --- a/usr.sbin/ospf6d/rde_lsdb.c +++ b/usr.sbin/ospf6d/rde_lsdb.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rde_lsdb.c,v 1.11 2008/12/28 21:20:34 claudio Exp $ */ +/* $OpenBSD: rde_lsdb.c,v 1.12 2008/12/30 21:31:54 claudio Exp $ */ /* * Copyright (c) 2004, 2005 Claudio Jeker <claudio@openbsd.org> @@ -628,6 +628,10 @@ lsa_dump(struct lsa_tree *tree, int imsg_type, pid_t pid) if (v->type == LSA_TYPE_EXTERNAL) break; continue; + case IMSG_CTL_SHOW_DB_LINK: + if (v->type == LSA_TYPE_LINK) + break; + continue; case IMSG_CTL_SHOW_DB_NET: if (v->type == LSA_TYPE_NETWORK) break; |