How is a Gin Rummy hand scored if both the knocking and defending player have Gin?
Your opponent gets 25 points plus 0 points. You do not get a chance to undercut. According to Pagat:


  A player who goes gin can never be undercut.


You do not get a gin bonus because you did not declare gin. You don't have a chance to declare gin because play ended. Play ended because your opponent knocked. Again from Pagat, emphasis mine:


  You can end the play at your turn if [...] Ending the play in this way is known as knocking [...]