@@ -1416,6 +1416,7 @@ bgp_attr_malformed(struct bgp_attr_parser_args *args, uint8_t subcode,
14161416 case BGP_ATTR_LARGE_COMMUNITIES :
14171417 case BGP_ATTR_ORIGINATOR_ID :
14181418 case BGP_ATTR_CLUSTER_LIST :
1419+ case BGP_ATTR_ENCAP :
14191420 case BGP_ATTR_OTC :
14201421 return BGP_ATTR_PARSE_WITHDRAW ;
14211422 case BGP_ATTR_MP_REACH_NLRI :
@@ -2644,39 +2645,33 @@ bgp_attr_ipv6_ext_communities(struct bgp_attr_parser_args *args)
26442645}
26452646
26462647/* Parse Tunnel Encap attribute in an UPDATE */
2647- static int bgp_attr_encap (uint8_t type , struct peer * peer , /* IN */
2648- bgp_size_t length , /* IN: attr's length field */
2649- struct attr * attr , /* IN: caller already allocated */
2650- uint8_t flag , /* IN: attr's flags field */
2651- uint8_t * startp )
2648+ static int bgp_attr_encap (struct bgp_attr_parser_args * args )
26522649{
2653- bgp_size_t total ;
26542650 uint16_t tunneltype = 0 ;
2655-
2656- total = length + (CHECK_FLAG (flag , BGP_ATTR_FLAG_EXTLEN ) ? 4 : 3 );
2651+ struct peer * const peer = args -> peer ;
2652+ struct attr * const attr = args -> attr ;
2653+ bgp_size_t length = args -> length ;
2654+ uint8_t type = args -> type ;
2655+ uint8_t flag = args -> flags ;
26572656
26582657 if (!CHECK_FLAG (flag , BGP_ATTR_FLAG_TRANS )
26592658 || !CHECK_FLAG (flag , BGP_ATTR_FLAG_OPTIONAL )) {
2660- zlog_info (
2661- "Tunnel Encap attribute flag isn't optional and transitive %d" ,
2662- flag );
2663- bgp_notify_send_with_data (peer , BGP_NOTIFY_UPDATE_ERR ,
2664- BGP_NOTIFY_UPDATE_ATTR_FLAG_ERR ,
2665- startp , total );
2666- return -1 ;
2659+ zlog_err ("Tunnel Encap attribute flag isn't optional and transitive %d" ,
2660+ flag );
2661+ return bgp_attr_malformed (args , BGP_NOTIFY_UPDATE_OPT_ATTR_ERR ,
2662+ args -> total );
26672663 }
26682664
26692665 if (BGP_ATTR_ENCAP == type ) {
26702666 /* read outer TLV type and length */
26712667 uint16_t tlv_length ;
26722668
26732669 if (length < 4 ) {
2674- zlog_info (
2670+ zlog_err (
26752671 "Tunnel Encap attribute not long enough to contain outer T,L" );
2676- bgp_notify_send_with_data (
2677- peer , BGP_NOTIFY_UPDATE_ERR ,
2678- BGP_NOTIFY_UPDATE_OPT_ATTR_ERR , startp , total );
2679- return -1 ;
2672+ return bgp_attr_malformed (args ,
2673+ BGP_NOTIFY_UPDATE_OPT_ATTR_ERR ,
2674+ args -> total );
26802675 }
26812676 tunneltype = stream_getw (BGP_INPUT (peer ));
26822677 tlv_length = stream_getw (BGP_INPUT (peer ));
@@ -2706,13 +2701,11 @@ static int bgp_attr_encap(uint8_t type, struct peer *peer, /* IN */
27062701 }
27072702
27082703 if (sublength > length ) {
2709- zlog_info (
2710- "Tunnel Encap attribute sub-tlv length %d exceeds remaining length %d" ,
2711- sublength , length );
2712- bgp_notify_send_with_data (
2713- peer , BGP_NOTIFY_UPDATE_ERR ,
2714- BGP_NOTIFY_UPDATE_OPT_ATTR_ERR , startp , total );
2715- return -1 ;
2704+ zlog_err ("Tunnel Encap attribute sub-tlv length %d exceeds remaining length %d" ,
2705+ sublength , length );
2706+ return bgp_attr_malformed (args ,
2707+ BGP_NOTIFY_UPDATE_OPT_ATTR_ERR ,
2708+ args -> total );
27162709 }
27172710
27182711 /* alloc and copy sub-tlv */
@@ -2760,13 +2753,10 @@ static int bgp_attr_encap(uint8_t type, struct peer *peer, /* IN */
27602753
27612754 if (length ) {
27622755 /* spurious leftover data */
2763- zlog_info (
2764- "Tunnel Encap attribute length is bad: %d leftover octets" ,
2765- length );
2766- bgp_notify_send_with_data (peer , BGP_NOTIFY_UPDATE_ERR ,
2767- BGP_NOTIFY_UPDATE_OPT_ATTR_ERR ,
2768- startp , total );
2769- return -1 ;
2756+ zlog_err ("Tunnel Encap attribute length is bad: %d leftover octets" ,
2757+ length );
2758+ return bgp_attr_malformed (args , BGP_NOTIFY_UPDATE_OPT_ATTR_ERR ,
2759+ args -> total );
27702760 }
27712761
27722762 return 0 ;
@@ -3690,8 +3680,7 @@ enum bgp_attr_parse_ret bgp_attr_parse(struct peer *peer, struct attr *attr,
36903680 case BGP_ATTR_VNC :
36913681#endif
36923682 case BGP_ATTR_ENCAP :
3693- ret = bgp_attr_encap (type , peer , length , attr , flag ,
3694- startp );
3683+ ret = bgp_attr_encap (& attr_args );
36953684 break ;
36963685 case BGP_ATTR_PREFIX_SID :
36973686 ret = bgp_attr_prefix_sid (& attr_args );
0 commit comments