Solution by OronSH/gghx.
Let P(x,y) denote the assertion
f(xf(x)+xy)=f(x)2+f(x)f(y).
The functions
f(x)≡0,f(x)≡21,f(x)=x
all work. We prove these are the only ones.
Taking P(0,y) gives
f(0)=f(0)2+f(0)f(y).
If f(0)=0, then f(y) is constant, and this gives f≡21. Hence, apart from the constant solutions, we may assume
f(0)=0.
If f(c)=0, then P(c,y) gives
f(cy)=0
for every real y. In the nonconstant case this forces c=0, so 0 has the unique preimage 0.
Now P(x,−f(x)) gives
0=f(x)(f(x)+f(−f(x))).
Thus, whenever f(x)=0,
f(−f(x))=−f(x).(1)
For f(x)=0, the same equality follows from f(0)=0, so (1) holds for every x.
Finally, applying P(−f(y),y) and using (1) gives
f(−yf(y)+f(y)2)=0.
By the uniqueness of the zero,
f(y)2=yf(y)
for every y. Hence either f(y)=0, which implies y=0, or f(y)=y. Therefore f(y)=y for all real y.
So the solutions are
f(x)≡0,f(x)≡21,f(x)=x.