This is legal as long as only stick to stick contact is made. This is another all-encompassing rule that prevents a player from impeding a player not in possession of the puck. There are many interpretations of this rule, and it is best left for you to look at in the rulebook. In most cases, interference results in a minor penalty. When a player is ejected, a game misconduct is called against the player.
Some penalties also carry an automatic game misconduct.
A player may also receive a 10 minute misconduct if the incident does not merit ejection. If a player or team official deliberately injures or attempts to injure a player, official, or team official, then a gross misconduct is called. All of these are signaled the same way by the referee. This might be a punch with the gloves on, or excessive pushing and shoving after the whistle is blown. Roughing is always a minor penalty.