@@ -119,6 +119,14 @@ async def add_address(self, address):
119
119
if self .nl :
120
120
await self .nl .notify_newaddr (address )
121
121
122
+ async def del_address (self , address ):
123
+ addr = self .lookup_address (address .iface , address .eid )
124
+ if not addr :
125
+ raise NetlinkError (errno .ENOENT )
126
+ self .addresses .remove (addr )
127
+ if self .nl :
128
+ await self .nl .notify_deladdr (address )
129
+
122
130
async def add_neighbour (self , neigh ):
123
131
if self .lookup_neighbour (neigh .iface , neigh .eid ):
124
132
raise NetlinkError (errno .EEXIST )
@@ -166,6 +174,12 @@ def lookup_neighbour(self, iface, eid):
166
174
return neighbour
167
175
return None
168
176
177
+ def lookup_address (self , iface , eid ):
178
+ for address in self .addresses :
179
+ if address .iface == iface and address .eid == eid :
180
+ return address
181
+ return None
182
+
169
183
def find_endpoint (self , addr ):
170
184
iface = None
171
185
lladdr = None
@@ -725,14 +739,20 @@ async def _handle_getaddr(self, msg):
725
739
726
740
await self ._send_msg (buf )
727
741
728
- async def notify_newaddr (self , addr ):
729
- msg = self ._create_msg (ifaddrmsg_mctp , rtnl . RTM_NEWADDR , 0 )
742
+ async def _notify_addr (self , addr , typ ):
743
+ msg = self ._create_msg (ifaddrmsg_mctp , typ , 0 )
730
744
self ._format_addr (msg , addr )
731
745
buf = bytearray ()
732
746
msg .encode ()
733
747
buf .extend (msg .data )
734
748
await self ._send_msg (buf )
735
749
750
+ async def notify_newaddr (self , addr ):
751
+ await self ._notify_addr (addr , rtnl .RTM_NEWADDR )
752
+
753
+ async def notify_deladdr (self , addr ):
754
+ await self ._notify_addr (addr , rtnl .RTM_DELADDR )
755
+
736
756
def _format_neigh (self , msg , neigh ):
737
757
msg ['ifindex' ] = neigh .iface .ifindex
738
758
msg ['attrs' ] = [
0 commit comments