Scapy BGP Flags Attribute
<p><strong>Is there any other way I could use Scapy to configure a packet with multiple flag attributes?</strong></p>

<p>I am trying to set up a BGP Layer with both optional and transitive attributes. I am using this github file: <a href="https://github.com/levigross/Scapy/blob/master/scapy/contrib/bgp.py" rel="nofollow">https://github.com/levigross/Scapy/blob/master/scapy/contrib/bgp.py</a>. On line 107, is the flags I am trying to add. </p>

<p>Past failed attempts include:</p>

<pre><code>&gt;&gt;&gt;a=BGPPathAttribute(flags=["Optional","Transitive"])
&gt;&gt;&gt;send(a)
TypeError: unsupported operand type(s) for &amp;: 'str' and 'int'

&gt;&gt;&gt;a=BGPPathAttribute(flags=("Optional","Transitive"))
&gt;&gt;&gt;send(a)
TypeError: unsupported operand type(s) for &amp;: 'tuple' and 'int'

&gt;&gt;&gt;a=BGPPathAttribute(flags="Optional")/BGPPathAttribute(flags="Transitive") 
Creates 2 separate path attributes: One which is Optional and Non-Transitive and the other which is Well Known and Transitive.

&gt;&gt;&gt;a=BGPPathAttribute(flags="Optional", flags="Transitive")
SyntaxError: keyword argument repeated

&gt;&gt;&gt;a=BGPPathAttribute(flags="OT")
ValueError: ['OT'] is not in list
</code></pre>

<p>It is possible to configure multiple flag attributes by enumerating them in a single string, delimited with the <code>'+'</code> sign:</p>

<pre class="lang-py prettyprint-override"><code>In [1]: from scapy.all import *
WARNING: No route found for IPv6 destination :: (no default route?)

In [2]: from scapy.contrib.bgp import BGPPathAttribute

In [3]: BGPPathAttribute(flags='Optional+Transitive')
Out[3]: &lt;BGPPathAttribute  flags=Transitive+Optional |&gt;

In [4]: send(_)
WARNING: Mac address to reach destination not found. Using broadcast.
.
Sent 1 packets.
</code></pre>

<hr>

<p>An alternative method, to directly calculate the numerical value of the desired combination of flags, is provided for completeness' sake:</p>

<pre><code>In [1]: from scapy.all import *
WARNING: No route found for IPv6 destination :: (no default route?)

In [2]: from scapy.contrib.bgp import BGPPathAttribute

In [3]: BGPPathAttribute(flags='Optional').flags | BGPPathAttribute(flags='Transitive').flags
Out[3]: 192

In [4]: BGPPathAttribute(flags=_)
Out[4]: &lt;BGPPathAttribute  flags=Transitive+Optional |&gt;

In [5]: send(_)
WARNING: Mac address to reach destination not found. Using broadcast.
.
Sent 1 packets.
</code></pre>

python networking scapy bgp