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
F106132771: D21240.diff
Wed, Dec 25, 10:51 PM
Unknown Object (File)
Sat, Dec 14, 3:26 AM
Unknown Object (File)
Sat, Nov 30, 3:43 AM
Unknown Object (File)
Nov 20 2024, 4:36 AM
Unknown Object (File)
Nov 20 2024, 4:34 AM
Unknown Object (File)
Nov 20 2024, 4:22 AM
Unknown Object (File)
Nov 20 2024, 4:19 AM
Unknown Object (File)
Nov 20 2024, 2:39 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

Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 27346
Build 25597: arc lint + arc unit

Event Timeline

afedorov added inline comments.
sys/net/ethernet.h
79

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

sys/net/ethernet.h
79

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.