Callback that sends an RA with a 0 lifetime
(req, reply_mac, tgt_mac, iface)
| 4050 | return 1 |
| 4051 | |
| 4052 | def ra_reply_callback(req, reply_mac, tgt_mac, iface): |
| 4053 | """ |
| 4054 | Callback that sends an RA with a 0 lifetime |
| 4055 | """ |
| 4056 | |
| 4057 | # Let's build a reply and send it |
| 4058 | |
| 4059 | src = req[IPv6].src |
| 4060 | |
| 4061 | # Prepare packets parameters |
| 4062 | ether_params = {} |
| 4063 | if reply_mac: |
| 4064 | ether_params["src"] = reply_mac |
| 4065 | |
| 4066 | if tgt_mac: |
| 4067 | ether_params["dst"] = tgt_mac |
| 4068 | |
| 4069 | # Basis of fake RA (high pref, zero lifetime) |
| 4070 | rep = Ether(**ether_params) / IPv6(src=src, dst="ff02::1") |
| 4071 | rep /= ICMPv6ND_RA(prf=1, routerlifetime=0) |
| 4072 | |
| 4073 | # Add it a PIO from the request ... |
| 4074 | tmp = req |
| 4075 | while ICMPv6NDOptPrefixInfo in tmp: |
| 4076 | pio = tmp[ICMPv6NDOptPrefixInfo] |
| 4077 | tmp = pio.payload |
| 4078 | del pio.payload |
| 4079 | rep /= pio |
| 4080 | |
| 4081 | # ... and source link layer address option |
| 4082 | if ICMPv6NDOptSrcLLAddr in req: |
| 4083 | mac = req[ICMPv6NDOptSrcLLAddr].lladdr |
| 4084 | else: |
| 4085 | mac = req[Ether].src |
| 4086 | rep /= ICMPv6NDOptSrcLLAddr(lladdr=mac) |
| 4087 | |
| 4088 | sendp(rep, iface=iface, verbose=0) |
| 4089 | |
| 4090 | print("Fake RA sent with source address %s" % src) |
| 4091 | |
| 4092 | if not iface: |
| 4093 | iface = conf.iface |
no test coverage detected