Page MenuHomeFreeBSD

net: add ETHER_IS_ZERO macro similar to ETHER_IS_BROADCAST
ClosedPublic

Authored by jacob.e.keller_intel.com on Aug 12 2019, 10:53 PM.
Tags
None
Referenced Files
F80142313: D21240.id63943.diff
Thu, Mar 28, 12:31 PM
Unknown Object (File)
Feb 15 2024, 1:53 AM
Unknown Object (File)
Feb 12 2024, 6:40 AM
Unknown Object (File)
Feb 10 2024, 2:41 AM
Unknown Object (File)
Dec 20 2023, 7:44 PM
Unknown Object (File)
Dec 10 2023, 9:56 PM
Unknown Object (File)
Nov 24 2023, 2:06 PM
Unknown Object (File)
Nov 15 2023, 8:01 PM

Details

Summary

Some places in network code may need to verify that an ethernet address
is not the 'zero' address. Provide a standard macro ETHER_IS_ZERO for
this purpose, similar to the ETHER_IS_BROADCAST macro already available.

Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

afedorov added inline comments.
sys/net/ethernet.h
79 ↗(On Diff #60699)

Is this correct? If one byte of mac address is equal zero than the whole expression equal 0x00.

sys/net/ethernet.h
79 ↗(On Diff #60699)

Yea, this is incorrect, woops. Should be bitwise or.

Use bitwise OR instead of bitwise AND to correct implementation

It’s seems I found another incorrect solution:

#include <stdio.h>

int main()
{

unsigned char a = (1 << 0) ||(1<<1)||(1 <<2)||(1<<3)||(1<<4)||(1<<5);
printf("momentum more : %d\n", a);

return 0;

}

In D21240#462131, @aleksandr.fedorov_itglobal.com wrote:

It’s seems I found another incorrect solution:

#include <stdio.h>

int main()
{

unsigned char a = (1 << 0) ||(1<<1)||(1 <<2)||(1<<3)||(1<<4)||(1<<5);
printf("momentum more : %d\n", a);

return 0;

}

In D21240#462131, @aleksandr.fedorov_itglobal.com wrote:

It’s seems I found another incorrect solution:

#include <stdio.h>

int main()
{

unsigned char a = (1 << 0) ||(1<<1)||(1 <<2)||(1<<3)||(1<<4)||(1<<5);
printf("momentum more : %d\n", a);

return 0;

}

This uses boolean ||, not bitwise |

bitwise OR should correctly combine all of the chunks of the MAC address, and if any are non-zero, the whole thing will be non-zero.

Ops, you’re right. Sorry for the noise.

This revision is now accepted and ready to land.Nov 4 2019, 9:50 PM
erj requested changes to this revision.Nov 4 2019, 9:57 PM

I get a build error with this revision:

--- if_ure.o ---
/root/srcs/head/src/sys/dev/usb/net/if_ure.c:71:9: error: 'ETHER_IS_ZERO' macro redefined [-Werror,-Wmacro-redefined]
#define ETHER_IS_ZERO(addr) \
        ^
/root/srcs/head/src/sys/net/ethernet.h:77:9: note: previous definition is here
#define ETHER_IS_ZERO(addr) \
        ^
1 error generated.
This revision now requires changes to proceed.Nov 4 2019, 9:57 PM

Remove ETHER_IS_ZERO definitions from USB networking drivers.

This revision was not accepted when it landed; it landed in state Needs Review.Nov 5 2019, 12:12 AM
This revision was automatically updated to reflect the committed changes.