Two patches. The first has l2tpd pass the calling number (if supplied) from the calling number AVP into l2tp_session_lns_handle_incoming_call()'s calling number parameter (as suggested by the "TODO" comment before said call).
The second is a patch to the sync-pppd handler which places the calling number and the peer host name into the environment variables L2TP_CALLING_NUM and
Note that the Linux /usr/sbin/pppd clobbers the environment before calling any of its scripts such as ip-up, so you need to get at the environment before pppd gets its hands on it. Do this by having l2tpd call a script which in turn calls pppd, e.g. in /etc/l2tp/l2tp.conf:
then have /etc/l2tp/pppd-wrapper do something like:
exec /usr/sbin/pppd "$@" ipparam "$L2TP_CALLING_NUM"
This will cause pppd to pass the calling number to /etc/ppp/ip-up as $6.