ethernet: refactor the redundant code