Diff for /embedaddon/libnet/src/libnet_build_bgp.c between versions 1.1 and 1.1.1.3

version 1.1, 2012/02/21 22:14:23 version 1.1.1.3, 2023/09/27 11:11:38
Line 30 Line 30
  *   *
  */   */
   
#if (HAVE_CONFIG_H)#include "common.h"
#include "../include/config.h" 
#endif 
#if (!(_WIN32) || (__CYGWIN__))  
#include "../include/libnet.h" 
#else 
#include "../include/win32/libnet.h" 
#endif 
   
 libnet_ptag_t  libnet_ptag_t
libnet_build_bgp4_header(u_int8_t marker[LIBNET_BGP4_MARKER_SIZE], libnet_build_bgp4_header(uint8_t marker[LIBNET_BGP4_MARKER_SIZE],
       u_int16_t len, u_int8_t type, u_int8_t *payload, u_int32_t payload_s,uint16_t len, uint8_t type, const uint8_t *payload, uint32_t payload_s,
       libnet_t *l, libnet_ptag_t ptag)libnet_t *l, libnet_ptag_t ptag)
 {  {
    u_int32_t n, h;    uint32_t n, h;
     libnet_pblock_t *p;      libnet_pblock_t *p;
     struct libnet_bgp4_header_hdr bgp4_hdr;      struct libnet_bgp4_header_hdr bgp4_hdr;
   
Line 66  libnet_build_bgp4_header(u_int8_t marker[LIBNET_BGP4_M Line 59  libnet_build_bgp4_header(u_int8_t marker[LIBNET_BGP4_M
         return (-1);          return (-1);
     }      }
   
        memset(&bgp4_hdr, 0, sizeof(bgp4_hdr));    memset(&bgp4_hdr, 0, sizeof(bgp4_hdr));
        memcpy(bgp4_hdr.marker, marker, LIBNET_BGP4_MARKER_SIZE * sizeof (u_int8_t));    memcpy(bgp4_hdr.marker, marker, LIBNET_BGP4_MARKER_SIZE * sizeof(uint8_t));
     bgp4_hdr.len = htons(len);      bgp4_hdr.len = htons(len);
     bgp4_hdr.type = type;      bgp4_hdr.type = type;
   
    n = libnet_pblock_append(l, p, (u_int8_t *)&bgp4_hdr, LIBNET_BGP4_HEADER_H);    n = libnet_pblock_append(l, p, (uint8_t *)&bgp4_hdr, LIBNET_BGP4_HEADER_H);
     if (n == -1)      if (n == -1)
     {      {
         goto bad;          goto bad;
     }      }
   
    if ((payload && !payload_s) || (!payload && payload_s))    /* boilerplate payload sanity check / append macro */
    {    LIBNET_DO_PAYLOAD(l, p);
         snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, 
                             "%s(): payload inconsistency\n", __func__); 
        goto bad; 
    } 
 
    if (payload && payload_s) 
    { 
        n = libnet_pblock_append(l, p, payload, payload_s); 
        if (n == -1) 
        { 
            /* err msg set in libnet_pblock_append() */ 
            goto bad; 
        } 
    } 
     
     return (ptag ? ptag : libnet_pblock_update(l, p, h,      return (ptag ? ptag : libnet_pblock_update(l, p, h,
             LIBNET_PBLOCK_BGP4_HEADER_H));              LIBNET_PBLOCK_BGP4_HEADER_H));
 bad:  bad:
Line 102  bad: Line 81  bad:
 }  }
   
 libnet_ptag_t  libnet_ptag_t
libnet_build_bgp4_open(u_int8_t version, u_int16_t src_as, u_int16_t hold_time,libnet_build_bgp4_open(uint8_t version, uint16_t src_as, uint16_t hold_time,
            u_int32_t bgp_id, u_int8_t opt_len, u_int8_t *payload, u_int32_t payload_s,uint32_t bgp_id, uint8_t opt_len, const uint8_t *payload, uint32_t payload_s,
            libnet_t *l, libnet_ptag_t ptag)libnet_t *l, libnet_ptag_t ptag)
 {  {
    u_int32_t n, h;    uint32_t n, h;
     libnet_pblock_t *p;      libnet_pblock_t *p;
    u_int16_t val;    uint16_t val;
   
     if (l == NULL)      if (l == NULL)
     {       { 
Line 129  libnet_build_bgp4_open(u_int8_t version, u_int16_t src Line 108  libnet_build_bgp4_open(u_int8_t version, u_int16_t src
     }      }
   
     /* for memory alignment reason, we need to append each field separately */      /* for memory alignment reason, we need to append each field separately */
    n = libnet_pblock_append(l, p, (u_int8_t *)&version, sizeof (version));    n = libnet_pblock_append(l, p, (uint8_t *)&version, sizeof (version));
     if (n == -1)      if (n == -1)
     {      {
         goto bad;          goto bad;
     }      }
   
     val = htons(src_as);      val = htons(src_as);
    n = libnet_pblock_append(l, p, (u_int8_t *)&val, sizeof(src_as));    n = libnet_pblock_append(l, p, (uint8_t *)&val, sizeof(src_as));
     if (n == -1)      if (n == -1)
     {      {
         goto bad;          goto bad;
     }      }
   
     val = htons(hold_time);      val = htons(hold_time);
    n = libnet_pblock_append(l, p, (u_int8_t *)&val, sizeof(hold_time));    n = libnet_pblock_append(l, p, (uint8_t *)&val, sizeof(hold_time));
     if (n == -1)      if (n == -1)
     {      {
         goto bad;          goto bad;
     }      }
   
     n = htonl(bgp_id);      n = htonl(bgp_id);
    n = libnet_pblock_append(l, p, (u_int8_t *)&n, sizeof(bgp_id));    n = libnet_pblock_append(l, p, (uint8_t *)&n, sizeof(bgp_id));
     if (n == -1)      if (n == -1)
     {      {
         goto bad;          goto bad;
     }      }
   
    n = libnet_pblock_append(l, p, (u_int8_t *)&opt_len, sizeof(opt_len));    n = libnet_pblock_append(l, p, (uint8_t *)&opt_len, sizeof(opt_len));
     if (n == -1)      if (n == -1)
     {      {
         goto bad;          goto bad;
     }      }
   
    if ((payload && !payload_s) || (!payload && payload_s))    /* boilerplate payload sanity check / append macro */
    {    LIBNET_DO_PAYLOAD(l, p);
         snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, 
                             "%s(): payload inconsistency\n", __func__); 
        goto bad; 
    } 
 
    if (payload && payload_s) 
    { 
        n = libnet_pblock_append(l, p, payload, payload_s); 
        if (n == -1) 
        { 
            /* err msg set in libnet_pblock_append() */ 
            goto bad; 
        } 
    } 
     
     return (ptag ? ptag : libnet_pblock_update(l, p, h,      return (ptag ? ptag : libnet_pblock_update(l, p, h,
            LIBNET_PBLOCK_BGP4_OPEN_H));             LIBNET_PBLOCK_BGP4_OPEN_H));
 bad:  bad:
Line 187  bad: Line 152  bad:
 }  }
   
 libnet_ptag_t  libnet_ptag_t
libnet_build_bgp4_update(u_int16_t unfeasible_rt_len, u_int8_t *withdrawn_rt,libnet_build_bgp4_update(uint16_t unfeasible_rt_len, const uint8_t *withdrawn_rt,
            u_int16_t total_path_attr_len, u_int8_t *path_attributes,uint16_t total_path_attr_len, const uint8_t *path_attributes, uint16_t info_len,
            u_int16_t info_len, u_int8_t *reachability_info,uint8_t *reachability_info, const uint8_t *payload, uint32_t payload_s,
            u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag)libnet_t *l, libnet_ptag_t ptag)
 {  {
    u_int32_t n, h;    uint32_t n, h;
     libnet_pblock_t *p;      libnet_pblock_t *p;
    u_int16_t length;    uint16_t length;
   
     if (l == NULL)      if (l == NULL)
     {       { 
Line 220  libnet_build_bgp4_update(u_int16_t unfeasible_rt_len,  Line 185  libnet_build_bgp4_update(u_int16_t unfeasible_rt_len, 
   
     /* for memory alignment reason, we need to append each field separately */      /* for memory alignment reason, we need to append each field separately */
     length = htons(unfeasible_rt_len);      length = htons(unfeasible_rt_len);
    n = libnet_pblock_append(l, p, (u_int8_t *)&length,     n = libnet_pblock_append(l, p, (uint8_t *)&length,
            sizeof (unfeasible_rt_len));        sizeof (unfeasible_rt_len));
     if (n == -1)      if (n == -1)
     {      {
         goto bad;          goto bad;
Line 237  libnet_build_bgp4_update(u_int16_t unfeasible_rt_len,  Line 202  libnet_build_bgp4_update(u_int16_t unfeasible_rt_len, 
     }      }
   
     length = htons(total_path_attr_len);      length = htons(total_path_attr_len);
    n = libnet_pblock_append(l, p, (u_int8_t *)&length,    n = libnet_pblock_append(l, p, (uint8_t *)&length,
             sizeof (total_path_attr_len));              sizeof (total_path_attr_len));
     if (n == -1)      if (n == -1)
     {      {
Line 262  libnet_build_bgp4_update(u_int16_t unfeasible_rt_len,  Line 227  libnet_build_bgp4_update(u_int16_t unfeasible_rt_len, 
         }          }
     }      }
   
    if ((payload && !payload_s) || (!payload && payload_s))    /* boilerplate payload sanity check / append macro */
    {    LIBNET_DO_PAYLOAD(l, p);
         snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, 
                             "%s(): payload inconsistency\n", __func__); 
        goto bad; 
    } 
 
    if (payload && payload_s) 
    { 
        n = libnet_pblock_append(l, p, payload, payload_s); 
        if (n == -1) 
        { 
            /* err msg set in libnet_pblock_append() */ 
            goto bad; 
        } 
    } 
     
     return (ptag ? ptag : libnet_pblock_update(l, p, h,      return (ptag ? ptag : libnet_pblock_update(l, p, h,
             LIBNET_PBLOCK_BGP4_UPDATE_H));              LIBNET_PBLOCK_BGP4_UPDATE_H));
 bad:  bad:
Line 287  bad: Line 238  bad:
 }  }
   
 libnet_ptag_t  libnet_ptag_t
libnet_build_bgp4_notification(u_int8_t err_code, u_int8_t err_subcode,libnet_build_bgp4_notification(uint8_t err_code, uint8_t err_subcode,
            u_int8_t *payload, u_int32_t payload_s, libnet_t *l, libnet_ptag_t ptag)const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
 {  {
    u_int32_t n, h;    uint32_t n, h;
     libnet_pblock_t *p;      libnet_pblock_t *p;
     struct libnet_bgp4_notification_hdr bgp4_hdr;      struct libnet_bgp4_notification_hdr bgp4_hdr;
   
Line 312  libnet_build_bgp4_notification(u_int8_t err_code, u_in Line 263  libnet_build_bgp4_notification(u_int8_t err_code, u_in
         return (-1);          return (-1);
     }      }
   
        memset(&bgp4_hdr, 0, sizeof(bgp4_hdr));    memset(&bgp4_hdr, 0, sizeof(bgp4_hdr));
        bgp4_hdr.err_code    = err_code;    bgp4_hdr.err_code    = err_code;
     bgp4_hdr.err_subcode = err_subcode;      bgp4_hdr.err_subcode = err_subcode;
   
    n = libnet_pblock_append(l, p, (u_int8_t *)&bgp4_hdr,    n = libnet_pblock_append(l, p, (uint8_t *)&bgp4_hdr,
             LIBNET_BGP4_NOTIFICATION_H);              LIBNET_BGP4_NOTIFICATION_H);
     if (n == -1)      if (n == -1)
     {      {
         goto bad;          goto bad;
     }      }
   
    if ((payload && !payload_s) || (!payload && payload_s))    /* boilerplate payload sanity check / append macro */
    {    LIBNET_DO_PAYLOAD(l, p);
         snprintf(l->err_buf, LIBNET_ERRBUF_SIZE, 
                             "%s(): payload inconsistency\n", __func__); 
        goto bad; 
    } 
 
    if (payload && payload_s) 
    { 
        n = libnet_pblock_append(l, p, payload, payload_s); 
        if (n == -1) 
        { 
            /* err msg set in libnet_pblock_append() */ 
            goto bad; 
        } 
    } 
           
     return (ptag ? ptag : libnet_pblock_update(l, p, h,      return (ptag ? ptag : libnet_pblock_update(l, p, h,
             LIBNET_PBLOCK_BGP4_NOTIFICATION_H));              LIBNET_PBLOCK_BGP4_NOTIFICATION_H));
Line 347  bad: Line 284  bad:
     return (-1);      return (-1);
 }  }
   
/* EOF *//**
  * Local Variables:
  *  indent-tabs-mode: nil
  *  c-file-style: "stroustrup"
  * End:
  */

Removed from v.1.1  
changed lines
  Added in v.1.1.1.3


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