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
Unknown Object (File)
Fri, Nov 15, 7:57 PM
Unknown Object (File)
Wed, Nov 13, 4:15 PM
Unknown Object (File)
Fri, Nov 1, 2:16 AM
Unknown Object (File)
Oct 17 2024, 12:09 AM
Unknown Object (File)
Oct 12 2024, 11:26 AM
Unknown Object (File)
Oct 7 2024, 7:41 AM
Unknown Object (File)
Sep 22 2024, 11:17 PM
Unknown Object (File)
Sep 21 2024, 1:23 AM

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.