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.

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
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

aleksandr.fedorov_itglobal.com 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;

}

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;

}

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.

lwhsu added a subscriber: scottl.Sep 14 2019, 1:37 PM
erj accepted this revision.Nov 4 2019, 9:50 PM
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.

erj accepted this revision as: erj.Nov 5 2019, 12:09 AM

Builds okay now.

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.