Annotation of embedaddon/libnet/src/libnet_build_ospf.c, revision 1.1.1.3

1.1       misho       1: /*
1.1.1.2   misho       2:  *  $Id: libnet_build_ospf.c,v 1.12 2004/11/09 07:05:07 mike Exp $
1.1       misho       3:  *
                      4:  *  libnet
                      5:  *  libnet_build_ospf.c - OSPF packet assembler
                      6:  *
                      7:  *  Copyright (c) 1998 - 2004 Mike D. Schiffman <mike@infonexus.com>
                      8:  *  All rights reserved.
                      9:  *
                     10:  *  Copyright (c) 1999, 2000 Andrew Reiter <areiter@bindview.com>
                     11:  *  Bindview Development
                     12:  *
                     13:  * Redistribution and use in source and binary forms, with or without
                     14:  * modification, are permitted provided that the following conditions
                     15:  * are met:
                     16:  * 1. Redistributions of source code must retain the above copyright
                     17:  *    notice, this list of conditions and the following disclaimer.
                     18:  * 2. Redistributions in binary form must reproduce the above copyright
                     19:  *    notice, this list of conditions and the following disclaimer in the
                     20:  *    documentation and/or other materials provided with the distribution.
                     21:  *
                     22:  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
                     23:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     24:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     25:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
                     26:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     27:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     28:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     29:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     30:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     31:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     32:  * SUCH DAMAGE.
                     33:  *
                     34:  */
                     35: 
1.1.1.3 ! misho      36: #include "common.h"
1.1       misho      37: 
                     38: libnet_ptag_t
1.1.1.2   misho      39: libnet_build_ospfv2(uint16_t len, uint8_t type, uint32_t rtr_id, 
                     40: uint32_t area_id, uint16_t sum, uint16_t autype, const uint8_t *payload, 
                     41: uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
1.1       misho      42: {
1.1.1.2   misho      43:     uint32_t n, h;
1.1       misho      44:     libnet_pblock_t *p;
                     45:     struct libnet_ospf_hdr ospf_hdr;
                     46: 
                     47:     if (l == NULL)
                     48:     { 
                     49:         return (-1);
                     50:     } 
                     51:  
                     52:     n = LIBNET_OSPF_H + payload_s;
                     53:     h = LIBNET_OSPF_H + payload_s + len;
                     54: 
                     55:     /*
                     56:      *  Find the existing protocol block if a ptag is specified, or create
                     57:      *  a new one.
                     58:      */
                     59:     p = libnet_pblock_probe(l, ptag, n, LIBNET_PBLOCK_OSPF_H);
                     60:     if (p == NULL)
                     61:     {
                     62:         return (-1);
                     63:     }
                     64:     
                     65:     memset(&ospf_hdr, 0, sizeof(ospf_hdr));
                     66:     ospf_hdr.ospf_v               = 2;              /* OSPF version 2 */
                     67:     ospf_hdr.ospf_type            = type;           /* Type of pkt */
                     68:     ospf_hdr.ospf_len             = htons(h);       /* Pkt len */
1.1.1.2   misho      69:     ospf_hdr.ospf_rtr_id.s_addr   = rtr_id;  /* Router ID */
                     70:     ospf_hdr.ospf_area_id.s_addr  = area_id; /* Area ID */
                     71:     ospf_hdr.ospf_sum             = sum;
1.1       misho      72:     ospf_hdr.ospf_auth_type       = htons(autype);  /* Type of auth */
                     73: 
1.1.1.2   misho      74:     n = libnet_pblock_append(l, p, (uint8_t *)&ospf_hdr, LIBNET_OSPF_H);
1.1       misho      75:     if (n == -1)
                     76:     {
                     77:         goto bad;
                     78:     }
                     79: 
1.1.1.2   misho      80:     /* boilerplate payload sanity check / append macro */
                     81:     LIBNET_DO_PAYLOAD(l, p);
1.1       misho      82: 
                     83:     if (sum == 0)
                     84:     {
                     85:         /*
                     86:          *  If checksum is zero, by default libnet will compute a checksum
                     87:          *  for the user.  The programmer can override this by calling
                     88:          *  libnet_toggle_checksum(l, ptag, 1);
                     89:          */
                     90:         libnet_pblock_setflags(p, LIBNET_PBLOCK_DO_CHECKSUM);
                     91:     }
                     92:     return (ptag ? ptag : libnet_pblock_update(l, p, h, LIBNET_PBLOCK_OSPF_H));
                     93: bad:
                     94:     libnet_pblock_delete(l, p);
                     95:     return (-1);
                     96: }
                     97: 
                     98: 
                     99: libnet_ptag_t
1.1.1.2   misho     100: libnet_build_ospfv2_hello(uint32_t netmask, uint16_t interval, uint8_t opts, 
                    101: uint8_t priority, uint32_t dead_int, uint32_t des_rtr, uint32_t bkup_rtr,
                    102: const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
1.1       misho     103: {
1.1.1.3 ! misho     104:        return libnet_build_ospfv2_hello_neighbor(netmask, interval, opts,
        !           105:                  priority, dead_int, des_rtr, bkup_rtr, 0,
        !           106:                  payload, payload_s, l, ptag);
        !           107: }
        !           108: 
        !           109: libnet_ptag_t
        !           110: libnet_build_ospfv2_hello_neighbor(uint32_t netmask, uint16_t interval, uint8_t opts,
        !           111: uint8_t priority, uint32_t dead_int, uint32_t des_rtr, uint32_t bkup_rtr, uint32_t neighbor,
        !           112: const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
        !           113: {
1.1.1.2   misho     114:     uint32_t n, h;
1.1       misho     115:     libnet_pblock_t *p;
                    116:     struct libnet_ospf_hello_hdr hello_hdr;
                    117: 
                    118:     if (l == NULL)
1.1.1.3 ! misho     119:     {
1.1       misho     120:         return (-1);
1.1.1.3 ! misho     121:     }
1.1       misho     122: 
                    123:     n = LIBNET_OSPF_HELLO_H + payload_s;
                    124:     h = 0;
                    125: 
                    126:     /*
                    127:      *  Find the existing protocol block if a ptag is specified, or create
                    128:      *  a new one.
                    129:      */
                    130:     p = libnet_pblock_probe(l, ptag, n, LIBNET_PBLOCK_OSPF_HELLO_H);
                    131:     if (p == NULL)
                    132:     {
                    133:         return (-1);
                    134:     }
1.1.1.3 ! misho     135: 
1.1       misho     136:     memset(&hello_hdr, 0, sizeof(hello_hdr));
1.1.1.2   misho     137:     hello_hdr.hello_nmask.s_addr    = netmask;  /* Netmask */
1.1       misho     138:     hello_hdr.hello_intrvl          = htons(interval); /* # seconds since last packet sent */
                    139:     hello_hdr.hello_opts            = opts;     /* OSPF_* options */
                    140:     hello_hdr.hello_rtr_pri         = priority; /* If 0, can't be backup */
                    141:     hello_hdr.hello_dead_intvl      = htonl(dead_int); /* Time til router is deemed down */
1.1.1.2   misho     142:     hello_hdr.hello_des_rtr.s_addr  = des_rtr; /* Networks designated router */
                    143:     hello_hdr.hello_bkup_rtr.s_addr = bkup_rtr; /* Networks backup router */
1.1.1.3 ! misho     144:     hello_hdr.hello_nbr.s_addr      = htonl(neighbor);
1.1       misho     145: 
1.1.1.2   misho     146:     n = libnet_pblock_append(l, p, (uint8_t *)&hello_hdr, LIBNET_OSPF_HELLO_H);
1.1       misho     147:     if (n == -1)
                    148:     {
                    149:         goto bad;
                    150:     }
                    151: 
1.1.1.2   misho     152:     /* boilerplate payload sanity check / append macro */
                    153:     LIBNET_DO_PAYLOAD(l, p);
1.1.1.3 ! misho     154: 
        !           155:     return (ptag ? ptag : libnet_pblock_update(l, p, h,
1.1       misho     156:             LIBNET_PBLOCK_OSPF_HELLO_H));
                    157: bad:
                    158:     libnet_pblock_delete(l, p);
                    159:     return (-1);
                    160: }
                    161: 
                    162: libnet_ptag_t
1.1.1.2   misho     163: libnet_build_ospfv2_dbd(uint16_t dgram_len, uint8_t opts, uint8_t type,
                    164: uint32_t seqnum, const uint8_t *payload, uint32_t payload_s, libnet_t *l,
1.1       misho     165: libnet_ptag_t ptag)
                    166: {
1.1.1.2   misho     167:     uint32_t n, h;
1.1       misho     168:     libnet_pblock_t *p;
                    169:     struct libnet_dbd_hdr dbd_hdr;
                    170: 
                    171:     if (l == NULL)
                    172:     { 
                    173:         return (-1);
                    174:     } 
                    175: 
                    176:     n = LIBNET_OSPF_DBD_H + payload_s;
                    177:     h = 0;
                    178: 
                    179:     /*
                    180:      *  Find the existing protocol block if a ptag is specified, or create
                    181:      *  a new one.
                    182:      */
                    183:     p = libnet_pblock_probe(l, ptag, n, LIBNET_PBLOCK_OSPF_DBD_H);
                    184:     if (p == NULL)
                    185:     {
                    186:         return (-1);
                    187:     }
                    188:     
                    189:     memset(&dbd_hdr, 0, sizeof(dbd_hdr));
                    190:     dbd_hdr.dbd_mtu_len        = htons(dgram_len); /* Max length of IP packet IF can use */
                    191:     dbd_hdr.dbd_opts    = opts;                    /* OSPF_* options */
                    192:     dbd_hdr.dbd_type    = type;                    /* Type of exchange occuring */
                    193:     dbd_hdr.dbd_seq     = htonl(seqnum);    /* DBD sequence number */
                    194: 
1.1.1.2   misho     195:     n = libnet_pblock_append(l, p, (uint8_t *)&dbd_hdr, LIBNET_OSPF_DBD_H);
1.1       misho     196:     if (n == -1)
                    197:     {
                    198:         goto bad;
                    199:     }
                    200: 
1.1.1.2   misho     201:     /* boilerplate payload sanity check / append macro */
                    202:     LIBNET_DO_PAYLOAD(l, p);
1.1       misho     203: 
                    204:     return (ptag ? ptag : libnet_pblock_update(l, p, h, 
                    205:             LIBNET_PBLOCK_OSPF_DBD_H));
                    206: bad:
                    207:     libnet_pblock_delete(l, p);
                    208:     return (-1);
                    209: }
                    210: 
                    211: 
                    212: libnet_ptag_t
1.1.1.3 ! misho     213: libnet_build_ospfv2_lsr(uint32_t type, uint32_t lsid, uint32_t advrtr, 
1.1.1.2   misho     214: const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
1.1       misho     215: {
1.1.1.2   misho     216:     uint32_t n, h;
1.1       misho     217:     libnet_pblock_t *p;
                    218:     struct libnet_lsr_hdr lsr_hdr;
                    219: 
                    220:     if (l == NULL)
                    221:     { 
                    222:         return (-1);
                    223:     } 
                    224: 
                    225:     n = LIBNET_OSPF_LSR_H + payload_s;
                    226:     h = 0;
                    227: 
                    228:     /*
                    229:      *  Find the existing protocol block if a ptag is specified, or create
                    230:      *  a new one.
                    231:      */
                    232:     p = libnet_pblock_probe(l, ptag, n, LIBNET_PBLOCK_OSPF_LSR_H);
                    233:     if (p == NULL)
                    234:     {
                    235:         return (-1);
                    236:     }
                    237: 
                    238:     memset(&lsr_hdr, 0, sizeof(lsr_hdr));
                    239:     lsr_hdr.lsr_type         = htonl(type);     /* Type of LS being requested */
                    240:     lsr_hdr.lsr_lsid        = htonl(lsid);     /* Link State ID */
                    241:     lsr_hdr.lsr_adrtr.s_addr = htonl(advrtr);   /* Advertising router */
                    242: 
1.1.1.2   misho     243:     n = libnet_pblock_append(l, p, (uint8_t *)&lsr_hdr, LIBNET_OSPF_LSR_H);
1.1       misho     244:     if (n == -1)
                    245:     {
                    246:         goto bad;
                    247:     }
                    248: 
1.1.1.2   misho     249:     /* boilerplate payload sanity check / append macro */
                    250:     LIBNET_DO_PAYLOAD(l, p);
1.1       misho     251: 
                    252:     return (ptag ? ptag : libnet_pblock_update(l, p, h, 
                    253:             LIBNET_PBLOCK_OSPF_LSR_H));
                    254: bad:
                    255:     libnet_pblock_delete(l, p);
                    256:     return (-1);
                    257: }
                    258: 
                    259: 
                    260: libnet_ptag_t
1.1.1.2   misho     261: libnet_build_ospfv2_lsu(uint32_t num, const uint8_t *payload, uint32_t payload_s,
1.1       misho     262: libnet_t *l, libnet_ptag_t ptag)
                    263: {
1.1.1.2   misho     264:     uint32_t n, h;
1.1       misho     265:     libnet_pblock_t *p;
                    266:     struct libnet_lsu_hdr lh_hdr;
                    267: 
                    268:     if (l == NULL)
                    269:     { 
                    270:         return (-1);
                    271:     } 
                    272: 
                    273:     n = LIBNET_OSPF_LSU_H + payload_s;
                    274:     h = 0;
                    275: 
                    276:     /*
                    277:      *  Find the existing protocol block if a ptag is specified, or create
                    278:      *  a new one.
                    279:      */
                    280:     p = libnet_pblock_probe(l, ptag, n, LIBNET_PBLOCK_OSPF_LSU_H);
                    281:     if (p == NULL)
                    282:     {
                    283:         return (-1);
                    284:     }
                    285: 
                    286:     memset(&lh_hdr, 0, sizeof(lh_hdr));
                    287:     lh_hdr.lsu_num = htonl(num);   /* Number of LSAs that will be bcasted */
                    288: 
1.1.1.2   misho     289:     n = libnet_pblock_append(l, p, (uint8_t *)&lh_hdr, LIBNET_OSPF_LSU_H);
1.1       misho     290:     if (n == -1)
                    291:     {
                    292:         goto bad;
                    293:     }
                    294: 
1.1.1.2   misho     295:     /* boilerplate payload sanity check / append macro */
                    296:     LIBNET_DO_PAYLOAD(l, p);
1.1       misho     297: 
                    298:     return (ptag ? ptag : libnet_pblock_update(l, p, h, 
                    299:             LIBNET_PBLOCK_OSPF_LSU_H));
                    300: bad:
                    301:     libnet_pblock_delete(l, p);
                    302:     return (-1);
                    303: }
                    304: 
                    305: 
                    306: libnet_ptag_t
1.1.1.3 ! misho     307: libnet_build_ospfv2_lsa(uint16_t age, uint8_t opts, uint8_t type, uint32_t lsid,
1.1.1.2   misho     308: uint32_t advrtr, uint32_t seqnum, uint16_t sum, uint16_t len,
                    309: const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
1.1       misho     310: {
1.1.1.2   misho     311:     uint32_t n, h;
1.1       misho     312:     libnet_pblock_t *p;
                    313:     struct libnet_lsa_hdr lsa_hdr;
                    314: 
                    315:     if (l == NULL)
                    316:     { 
                    317:         return (-1);
                    318:     } 
                    319: 
                    320:     n = LIBNET_OSPF_LSA_H + payload_s;
                    321:     h = len + payload_s;
                    322: 
                    323:     /*
                    324:      *  Find the existing protocol block if a ptag is specified, or create
                    325:      *  a new one.
                    326:      */
                    327:     p = libnet_pblock_probe(l, ptag, n, LIBNET_PBLOCK_OSPF_LSA_H);
                    328:     if (p == NULL)
                    329:     {
                    330:         return (-1);
                    331:     }
                    332: 
                    333:     memset(&lsa_hdr, 0, sizeof(lsa_hdr));
                    334:     lsa_hdr.lsa_age         = htons(age);
                    335:     lsa_hdr.lsa_opts        = opts;
                    336:     lsa_hdr.lsa_type        = type;
                    337:     lsa_hdr.lsa_id          = htonl(lsid);
                    338:     lsa_hdr.lsa_adv.s_addr  = htonl(advrtr);
                    339:     lsa_hdr.lsa_seq         = htonl(seqnum);
1.1.1.2   misho     340:     lsa_hdr.lsa_sum         = sum;
1.1       misho     341:     lsa_hdr.lsa_len         = htons(h);
                    342: 
1.1.1.2   misho     343:     n = libnet_pblock_append(l, p, (uint8_t *)&lsa_hdr, LIBNET_OSPF_LSA_H);
1.1       misho     344:     if (n == -1)
                    345:     {
                    346:         goto bad;
                    347:     }
                    348: 
1.1.1.2   misho     349:     /* boilerplate payload sanity check / append macro */
                    350:     LIBNET_DO_PAYLOAD(l, p);
1.1       misho     351: 
                    352:     if (sum == 0)
                    353:     {
                    354:         /*
                    355:          *  If checksum is zero, by default libnet will compute a checksum
                    356:          *  for the user.  The programmer can override this by calling
                    357:          *  libnet_toggle_checksum(l, ptag, 1);
                    358:          */
                    359:         libnet_pblock_setflags(p, LIBNET_PBLOCK_DO_CHECKSUM);
                    360:     }
                    361:     return (ptag ? ptag : libnet_pblock_update(l, p, h, 
                    362:             LIBNET_PBLOCK_OSPF_LSA_H));
                    363: bad:
                    364:     libnet_pblock_delete(l, p);
                    365:     return (-1);
                    366: }
                    367: 
                    368: 
                    369: libnet_ptag_t
1.1.1.2   misho     370: libnet_build_ospfv2_lsa_rtr(uint16_t flags, uint16_t num, uint32_t id,
                    371: uint32_t data, uint8_t type, uint8_t tos, uint16_t metric,
                    372: const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
1.1       misho     373: {
1.1.1.2   misho     374:     uint32_t n, h;
1.1       misho     375:     libnet_pblock_t *p;
                    376:     struct libnet_rtr_lsa_hdr rtr_lsa_hdr;
                    377: 
                    378:     if (l == NULL)
                    379:     { 
                    380:         return (-1);
                    381:     } 
                    382: 
                    383:     n = LIBNET_OSPF_LS_RTR_H + payload_s;
                    384:     h = 0;
                    385: 
                    386:     /*
                    387:      *  Find the existing protocol block if a ptag is specified, or create
                    388:      *  a new one.
                    389:      */
                    390:     p = libnet_pblock_probe(l, ptag, n, LIBNET_PBLOCK_LS_RTR_H);
                    391:     if (p == NULL)
                    392:     {
                    393:         return (-1);
                    394:     }
                    395: 
                    396:     memset(&rtr_lsa_hdr, 0, sizeof(rtr_lsa_hdr));
                    397:     rtr_lsa_hdr.rtr_flags       = htons(flags);
                    398:     rtr_lsa_hdr.rtr_num         = htons(num);
                    399:     rtr_lsa_hdr.rtr_link_id     = htonl(id);
                    400:     rtr_lsa_hdr.rtr_link_data   = htonl(data);
                    401:     rtr_lsa_hdr.rtr_type        = type;
                    402:     rtr_lsa_hdr.rtr_tos_num     = tos;
                    403:     rtr_lsa_hdr.rtr_metric      = htons(metric);
                    404: 
1.1.1.2   misho     405:     n = libnet_pblock_append(l, p, (uint8_t *)&rtr_lsa_hdr,
1.1       misho     406:             LIBNET_OSPF_LS_RTR_H);
                    407:     if (n == -1)
                    408:     {
                    409:         goto bad;
                    410:     }
                    411: 
1.1.1.2   misho     412:     /* boilerplate payload sanity check / append macro */
                    413:     LIBNET_DO_PAYLOAD(l, p);
1.1       misho     414: 
                    415:     return (ptag ? ptag : libnet_pblock_update(l, p, h, 
                    416:             LIBNET_PBLOCK_LS_RTR_H));
                    417: bad:
                    418:     libnet_pblock_delete(l, p);
                    419:     return (-1);
                    420: }
                    421: 
                    422: 
                    423: libnet_ptag_t
1.1.1.2   misho     424: libnet_build_ospfv2_lsa_net(uint32_t nmask, uint32_t rtrid,
                    425: const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
1.1       misho     426: {
1.1.1.2   misho     427:     uint32_t n, h;
1.1       misho     428:     libnet_pblock_t *p;
                    429:     struct libnet_net_lsa_hdr net_lsa_hdr;
                    430: 
                    431:     if (l == NULL)
                    432:     { 
                    433:         return (-1);
                    434:     } 
                    435: 
                    436:     n = LIBNET_OSPF_LS_NET_H + payload_s;
                    437:     h = 0;
                    438: 
                    439:     /*
                    440:      *  Find the existing protocol block if a ptag is specified, or create
                    441:      *  a new one.
                    442:      */
                    443:     p = libnet_pblock_probe(l, ptag, n, LIBNET_PBLOCK_LS_NET_H);
                    444:     if (p == NULL)
                    445:     {
                    446:         return (-1);
                    447:     }
                    448: 
                    449:     memset(&net_lsa_hdr, 0, sizeof(net_lsa_hdr));
                    450:     net_lsa_hdr.net_nmask.s_addr    = htonl(nmask);
                    451:     net_lsa_hdr.net_rtr_id          = htonl(rtrid);
                    452: 
1.1.1.2   misho     453:     n = libnet_pblock_append(l, p, (uint8_t *)&net_lsa_hdr,
1.1       misho     454:             LIBNET_OSPF_LS_NET_H);
                    455:     if (n == -1)
                    456:     {
                    457:         goto bad;
                    458:     }
                    459: 
1.1.1.2   misho     460:     /* boilerplate payload sanity check / append macro */
                    461:     LIBNET_DO_PAYLOAD(l, p);
1.1       misho     462: 
                    463:     return (ptag ? ptag : libnet_pblock_update(l, p, h, 
                    464:             LIBNET_PBLOCK_LS_NET_H));
                    465: bad:
                    466:     libnet_pblock_delete(l, p);
                    467:     return (-1);
                    468: }
                    469: 
                    470: 
                    471: libnet_ptag_t
1.1.1.3 ! misho     472: libnet_build_ospfv2_lsa_sum(uint32_t nmask, uint32_t metric, uint32_t tos, 
1.1.1.2   misho     473: const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
1.1       misho     474: {
1.1.1.2   misho     475:     uint32_t n, h;
1.1       misho     476:     libnet_pblock_t *p;
                    477:     struct libnet_sum_lsa_hdr sum_lsa_hdr;
                    478: 
                    479:     if (l == NULL)
                    480:     { 
                    481:         return (-1);
                    482:     } 
                    483: 
                    484:     n = LIBNET_OSPF_LS_SUM_H + payload_s;
                    485:     h = 0;
                    486: 
                    487:     /*
                    488:      *  Find the existing protocol block if a ptag is specified, or create
                    489:      *  a new one.
                    490:      */
                    491:     p = libnet_pblock_probe(l, ptag, n, LIBNET_PBLOCK_LS_SUM_H);
                    492:     if (p == NULL)
                    493:     {
                    494:         return (-1);
                    495:     }
                    496: 
                    497:     memset(&sum_lsa_hdr, 0, sizeof(sum_lsa_hdr));
                    498:     sum_lsa_hdr.sum_nmask.s_addr    = htonl(nmask);
                    499:     sum_lsa_hdr.sum_metric          = htonl(metric);
                    500:     sum_lsa_hdr.sum_tos_metric      = htonl(tos);
                    501: 
1.1.1.2   misho     502:     n = libnet_pblock_append(l, p, (uint8_t *)&sum_lsa_hdr,
1.1       misho     503:             LIBNET_OSPF_LS_SUM_H);
                    504:     if (n == -1)
                    505:     {
                    506:         goto bad;
                    507:     }
                    508: 
1.1.1.2   misho     509:     /* boilerplate payload sanity check / append macro */
                    510:     LIBNET_DO_PAYLOAD(l, p);
1.1       misho     511: 
                    512:     return (ptag ? ptag : libnet_pblock_update(l, p, h, 
                    513:             LIBNET_PBLOCK_LS_SUM_H));
                    514: bad:
                    515:     libnet_pblock_delete(l, p);
                    516:     return (-1);
                    517: }
                    518: 
                    519: 
                    520: libnet_ptag_t
1.1.1.3 ! misho     521: libnet_build_ospfv2_lsa_as(uint32_t nmask, uint32_t metric, uint32_t fwdaddr,
1.1.1.2   misho     522: uint32_t tag, const uint8_t *payload, uint32_t payload_s, libnet_t *l,
1.1       misho     523: libnet_ptag_t ptag)
                    524: {
1.1.1.2   misho     525:     uint32_t n, h;
1.1       misho     526:     libnet_pblock_t *p;
                    527:     struct libnet_as_lsa_hdr as_lsa_hdr;
                    528: 
                    529:     if (l == NULL)
                    530:     { 
                    531:         return (-1);
                    532:     } 
                    533:    
                    534:     n = LIBNET_OSPF_LS_AS_EXT_H + payload_s;
                    535:     h = 0;
                    536: 
                    537:     /*
                    538:      *  Find the existing protocol block if a ptag is specified, or create
                    539:      *  a new one.
                    540:      */
                    541:     p = libnet_pblock_probe(l, ptag, n, LIBNET_PBLOCK_LS_AS_EXT_H);
                    542:     if (p == NULL)
                    543:     {
                    544:         return (-1);
                    545:     }
                    546: 
                    547:     memset(&as_lsa_hdr, 0, sizeof(as_lsa_hdr));
                    548:     as_lsa_hdr.as_nmask.s_addr      = htonl(nmask);
                    549:     as_lsa_hdr.as_metric            = htonl(metric);
                    550:     as_lsa_hdr.as_fwd_addr.s_addr   = htonl(fwdaddr);
                    551:     as_lsa_hdr.as_rte_tag           = htonl(tag);
                    552: 
1.1.1.2   misho     553:     n = libnet_pblock_append(l, p, (uint8_t *)&as_lsa_hdr,
1.1       misho     554:             LIBNET_OSPF_LS_AS_EXT_H);
                    555:     if (n == -1)
                    556:     {
                    557:         goto bad;
                    558:     }
                    559: 
1.1.1.2   misho     560:     /* boilerplate payload sanity check / append macro */
                    561:     LIBNET_DO_PAYLOAD(l, p);
1.1       misho     562: 
                    563:     return (ptag ? ptag : libnet_pblock_update(l, p, h, 
                    564:             LIBNET_PBLOCK_LS_AS_EXT_H));
                    565: bad:
                    566:     libnet_pblock_delete(l, p);
                    567:     return (-1);
                    568: }
                    569: 
1.1.1.3 ! misho     570: /**
        !           571:  * Local Variables:
        !           572:  *  indent-tabs-mode: nil
        !           573:  *  c-file-style: "stroustrup"
        !           574:  * End:
        !           575:  */

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>