@@ -18,6 +18,7 @@ import (
1818//
1919// If `addr` is an IPv4 address and the broadcast address is not given, it
2020// will be automatically computed based on the IP mask if /30 or larger.
21+ // If `net.IPv4zero` is given as the broadcast address, broadcast is disabled.
2122func AddrAdd (link Link , addr * Addr ) error {
2223 return pkgHandle .AddrAdd (link , addr )
2324}
@@ -28,6 +29,7 @@ func AddrAdd(link Link, addr *Addr) error {
2829//
2930// If `addr` is an IPv4 address and the broadcast address is not given, it
3031// will be automatically computed based on the IP mask if /30 or larger.
32+ // If `net.IPv4zero` is given as the broadcast address, broadcast is disabled.
3133func (h * Handle ) AddrAdd (link Link , addr * Addr ) error {
3234 req := h .newNetlinkRequest (unix .RTM_NEWADDR , unix .NLM_F_CREATE | unix .NLM_F_EXCL | unix .NLM_F_ACK )
3335 return h .addrHandle (link , addr , req )
@@ -39,6 +41,7 @@ func (h *Handle) AddrAdd(link Link, addr *Addr) error {
3941//
4042// If `addr` is an IPv4 address and the broadcast address is not given, it
4143// will be automatically computed based on the IP mask if /30 or larger.
44+ // If `net.IPv4zero` is given as the broadcast address, broadcast is disabled.
4245func AddrReplace (link Link , addr * Addr ) error {
4346 return pkgHandle .AddrReplace (link , addr )
4447}
@@ -49,6 +52,7 @@ func AddrReplace(link Link, addr *Addr) error {
4952//
5053// If `addr` is an IPv4 address and the broadcast address is not given, it
5154// will be automatically computed based on the IP mask if /30 or larger.
55+ // If `net.IPv4zero` is given as the broadcast address, broadcast is disabled.
5256func (h * Handle ) AddrReplace (link Link , addr * Addr ) error {
5357 req := h .newNetlinkRequest (unix .RTM_NEWADDR , unix .NLM_F_CREATE | unix .NLM_F_REPLACE | unix .NLM_F_ACK )
5458 return h .addrHandle (link , addr , req )
@@ -57,18 +61,13 @@ func (h *Handle) AddrReplace(link Link, addr *Addr) error {
5761// AddrDel will delete an IP address from a link device.
5862//
5963// Equivalent to: `ip addr del $addr dev $link`
60- //
61- // If `addr` is an IPv4 address and the broadcast address is not given, it
62- // will be automatically computed based on the IP mask if /30 or larger.
6364func AddrDel (link Link , addr * Addr ) error {
6465 return pkgHandle .AddrDel (link , addr )
6566}
6667
6768// AddrDel will delete an IP address from a link device.
68- // Equivalent to: `ip addr del $addr dev $link`
6969//
70- // If `addr` is an IPv4 address and the broadcast address is not given, it
71- // will be automatically computed based on the IP mask if /30 or larger.
70+ // Equivalent to: `ip addr del $addr dev $link`
7271func (h * Handle ) AddrDel (link Link , addr * Addr ) error {
7372 req := h .newNetlinkRequest (unix .RTM_DELADDR , unix .NLM_F_ACK )
7473 return h .addrHandle (link , addr , req )
@@ -142,6 +141,10 @@ func (h *Handle) addrHandle(link Link, addr *Addr, req *nl.NetlinkRequest) error
142141 addr .Broadcast = calcBroadcast
143142 }
144143
144+ if net .IPv4zero .Equal (addr .Broadcast ) {
145+ addr .Broadcast = nil
146+ }
147+
145148 if addr .Broadcast != nil {
146149 req .AddData (nl .NewRtAttr (unix .IFA_BROADCAST , addr .Broadcast ))
147150 }
0 commit comments